Archived topic
Set height and width for the logo image
5 replies · Started by Dong on June 19, 2021
Hi guys,
I have the logo's explicit height and width issue:
https://developers.google.com/speed/pagespeed/insights/?url=dongknows.com
Currently, I have this issue with (just) the logo image. The code Elvin mentioned here:
fix the logo error but subequently caused the same error on ALL featured images of the Archive page. Here's the code I used:
add_filter( 'generate_logo_output','tu_logo_atts', 10, 2 );
function tu_logo_atts( $output, $logo ) {
printf(
'<div class="site-logo">
<a href="%1$s" title="%2$s" rel="home">
<img width="341" height="132" src="%3$s" alt="%2$s" />
</a>
</div>',
esc_url( apply_filters( 'generate_logo_href' , home_url( '/' ) ) ),
esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) ),
esc_url( apply_filters( 'generate_logo', $logo ) )
);
}
Please help!
Thanks,
-Dong.
Hi there,
see Tom's reply here:
https://generatepress.com/forums/topic/logo-does-not-have-explicit-width-and-height/#post-1762272
Make sure to only add the code that Tom provided there, the one you shared above is not required.
That fixed it. Thanks, David.
Glad to hear that!
Actually, David, I spoke too soon. The code caused the error on ALL the featured photos of the archive page.
Without the code, ONLY the logo had the issue.
Any advice?
Thanks,
-Dong.
Hi Dong,
I believe there's no need for this code if you're already using GP Premium 2.0 or newer.
To fix this, you simply have to reupload and reassign it again on the Site Identity settings. This should generate the missing attributes.
Note: The code snippet I've provided only works with the logo. It shouldn't affect any other images. https://github.com/tomusborne/generatepress/blob/b60b853630da6d9015722da903e53c8064148b0a/inc/structure/header.php#L151-L165