How to properly set custom logo size?

According to the Codex page about adding a Custom Logo, one has to add the following code to functions.php:

function themename_custom_logo_setup() {
    $defaults = array(
        'height'      = 100,
        'width'       = 400,
        'flex-height' = true,
        'flex-width'  = true,
        'header-text' = array( 'site-title', 'site-description' ),
    );
    add_theme_support( 'custom-logo', $defaults );
}
add_action( 'after_setup_theme', 'themename_custom_logo_setup' );

I'm not exactly sure about how the array values for height and width are used. The documentation says that are "expected sizes", but when I select an image in the customizer to be used a s a logo, it retains the original image size.

How are these values used? Do they define a custom image size name, in the same fashion as the builtin thumbnail, medium, large, and so on? And if it is so, what name it is, and how can I select it when using the the_custom_logo() function?


What I'm try to accomplish is to display the custom logo with a maximum image height, let's say 100px, and to let the width scale proportionally without distorting the picture, even if the size of the image loaded in the customizer is larger.

I'm not really sure on how to do this.

Adding a max-height CSS value in the stylesheet afterwards is not helping, because the the_custom_logo() function explicitly sets both height and width values inside the img / tag.

Topic logo functions images Wordpress

Category Web


I suspect the answer to your question is that, if height and width are specified in the array for the function, it will set the height and width of the logo on generation from the customizer menu. I'm pretty sure it does this by setting the crop dimensions, which you can then manually overwrite during generation. They don't define a custom image size name, if I'm understanding your meaning. What they do is literally append an inline width and height style to the image in the element. The image should maintain its proportions, however. CSS should overwrite the generation sizes, though. Check to be sure you don't have a CSS conflict. You might find that this question helps https://stackoverflow.com/questions/46700000/why-can-i-not-change-custom-logo-dimension-attributes-via-add-theme-support

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.