Archived topic
Logo does not have explicit width and height
24 replies · Started by ETO on April 13, 2021
Hello,
When I test my website with Google Pagespeed Insights, it says that the logo does not have explicit width and height. However, there was not such an error a few weeks ago although I haven't done any changes on the site.
Hi there,
Elvin's answer here should be helpful:
https://generatepress.com/forums/topic/tamano-recomendado-para-logo/#post-1696616
Let me know :)
Thanks, but I think this is a problem that should be fixed with a theme update. Why do I have to add extra code snippets to solve such a problem that should not exist at all?
Hi there,
It's one of the things Tom is working on for the next update. Please look forward to it. :)
Hello, Elvin!
You released the update and I updated my site but it seems that you haven't fixed this issue yet.
Hi there,
Are you still using the filter? Can you try removing it?
You then remove the logo on the customizer, save it, refresh the customizer page, and re-add it again. Let us know how it goes.
I don't use any filter and did what you asked (remove the logo on the customizer, save it, refresh the customizer page, and re-add it again). However, the problem still exists.
This fix didn't make it into the Navigation as Header option which you're using - our mistake.
For now, you need this filter:
add_filter( 'generate_logo_attributes', function( $attributes ) {
$data = wp_get_attachment_metadata( get_theme_mod( 'custom_logo' ) );
if ( ! empty( $data ) ) {
$attributes['width'] = $data['width'];
$attributes['height'] = $data['height'];
}
return $attributes;
} );
It will fix the issue and continue to work even when we fix it in the theme :)
Thanks, Tom but I would like to wait for the update to fix this issue. :)
Hello!
When will the update fixing this problem be released?
This will be in GP Premium 2.1 which doesn't have a release date right now.
However, this function I provided is update-safe and completely solves the problem: https://generatepress.com/forums/topic/logo-does-not-have-explicit-width-and-height/#post-1762272
There's no reason not to add it as a solution for now :)
Forgive this non-tech guy's question: WHERE do I add that code?
This article explains how to add that PHP Code:
https://docs.generatepress.com/article/adding-php/
TLDR: If you have a Child Theme installed then you paste the code into the Child Themes functions.php - NOT using a Child Theme ? Then install the Code Snippets plugin, create a new Snippet and paste the code in there.
Hey guys,
I've added this function but for some reason it isn't working but only on this website. On all the other websites I've added this function to it has fixed the issue. I've cleared cache several times but I still can't figure out why it isn't working on this website.
Hi Clayton,
Hey guys,
I’ve added this function but for some reason it isn’t working but only on this website. On all the other websites I’ve added this function to it has fixed the issue. I’ve cleared cache several times but I still can’t figure out why it isn’t working on this website.
Can you specify which one are you using?
If you're using GP Premium 2.0, you won't be needing the PHP snippet as it's already patched.
Once you've updated, you can remove and re-add the logo. This act should automatically generate the missing image height and width attribute.