Archived topic
Specify Height and Width for logo
17 replies · Started by Jill on April 21, 2021
Hello,
I need to specify the height and width of the logo on my blog. Given that google does not like my logo not having image dimensions, my issue is similar to the one found on this post:
https://generatepress.com/forums/topic/specify-image-dimensions-for-logo/
But...
I do not see a final solution offered. Could you please advise me as to how I can specify image size dimensions for my site logo?
I am using GP 2.4.2.
Thanks.
Hi there,
Any chance you can link us to the site in question?
You can use the private information field.
Let me know :)
Sure...
Are you currently using the Float version of the theme?
If so can you try switching to the Flex version?
You can check under Customizer > General.
Yes, I am using Float.
When I changed to Flex, it appeared in the preview pane as though this change would negatively affect the look of my site header. So I did not publish the changes.
If making this switch causes a negative effect, is reverting back fairly flawless?
Hi there,
you can change the structure - publish the changes. If something misbehaves then you can simply change the structure back again.
The flex version does seem to solve the height and width issue, but it causes other issues with my header layout. So, I switched back to Float.
Is there another way I can adjust the height and width issue that doesn't cause header layout issues?
Hi there,
You can try directing setting the image height and width attribute with this filter.
https://docs.generatepress.com/article/generate_logo_output/#setting-a-width-and-height
Example:
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="380" height="96" class="header-image" src="%3$s" alt="%2$s" title="%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 ) )
);
}
Excellent suggestion, thank you.
I added the filter to my child theme functions.php file but the logo height and width error still shows on the lighthouse report. Seems the logo is still not being delivered with a specific width and height dimensions. :(
I'd be pretty keen to know the answer to this one too.
I've followed the above, but instead of adding the filter to functions.php, I added it to the header.php file.
This is for my site https://www.greatbritishbucketlist.com/.
Any advice would be brilliant.
Cheers,
Macca
Have you resolved this?
Your logo already has width and height specified.
Make sure you are editing the theme's core files as they will be erased during updates.
Leo, if you are replying to me, no. I have not resolved this and my logo is not reporting a specific width and height according to the Lighthouse report viewer.
Hi Leo,
If it's appearing then great.
What do mean "Make sure you are editing the theme’s core files as they will be erased during updates."? I thought with GeneratePress it wasn't advised to use a child theme?
Cheers,
Macca
Jill - can you clear and disable your caching plugin first?
Elvin's PHP filter solution should work.
Macca - Please open a new topic for your question.
Thanks!
I cleared my cache. I'll have to wait until it's a slower traffic time before I'm willing to disable the caching plugin.