Archived topic
setting width/height to logo image
10 replies · Started by johnaps on May 26, 2021
Hello!
I have tried these
https://generatepress.com/forums/topic/how-to-set-height-and-width-for-the-logo-image/
and
https://generatepress.com/forums/topic/how-to-add-width-and-height-attributes-to-logo/
but first one doesnt work and second one adds a second logo next to my logo thus breaking my layout!
Is there any other way to apply width/height to my desktop logo (it applies for @media (min-width: 548px)) so i can fix this issue for pagespeed?
Hi there,
This should've been fixed with the latest GP Premium and GeneratePress versions.
Can you remove the filters you've used and reupload the image? To see if the image width and height attribute automatically assigns.
Let us know how it goes.
what filters do you mean???
i can reupload the image but i am not sure what filters are you referring to.
Hi there,
1. have you added any codes to change the behaviour of the logo ? If so remove them and go to step 2, if not just skip to step 2.
2. Remove you current logo, publish the changes and then reupload your logo. This should automatically add the width/height attribtues.
I did remove 2 filters i had in functions.php (on my staging)
add_filter( 'generate_logo_output', 'db_home_logo_htag', 10, 3 );
function db_home_logo_htag( $output, $logo_url, $html_attr ) {
if ( is_front_page() ) {
printf(
'<div class="site-logo">
<h1>
<a href="%1$s" title="%2$s" rel="home">
<img %3$s />
</a>
</h1>
</div>',
esc_url( apply_filters( 'generate_logo_href' , home_url( '/' ) ) ),
esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) ),
$html_attr
);
} else {
printf(
'<div class="site-logo">
<a href="%1$s" title="Σοφιανός Ορθοπεδικά Είδη Αθήνα" rel="home">
<img %3$s />
</a>
</div>',
esc_url( apply_filters( 'generate_logo_href' , home_url( '/' ) ) ),
esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) ),
$html_attr
);
}
}
and
function rocket_lazyload_exclude_class( $attributes ) {
$attributes[] = 'class="cropped-sofianos_logo_1-scaled-e1574776314321"';
return $attributes;
}
add_filter( 'rocket_lazyload_excluded_attributes', 'rocket_lazyload_exclude_class' );
and i removed the logo from customizer -> published and then added a new logo again...
Still the same html output without any width/height~
I provided admin credentials for my staging if you want to use them
I have also disabled all plugins except woocommerce and gp-premium in regards to my other unsolved support topic (https://generatepress.com/forums/topic/0-cart-number-doesnt-get-displayed/)
Hi there,
You're using the old floats structure which didn't have logo size attributes.
You can either:
a) Switch to flexbox: https://docs.generatepress.com/article/switching-from-floats-to-flexbox/
b) Use the below 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;
} );
Hi Tom!
Thank you so much for this!
Can you tell me if i ll see a big difference in real speed or pagespeed metrics at least if i switch to flexbox...?
Cause i checked enabling it on staging and the layout breaks are massive on my site.....
***If there is indeed a big speed pump up, is there any way to hire a anyone specialized in gp to tune my site to the flexbox layour according to how my live site currently looks? (that would be very much wanted if indeed there is a difference, no site should have the old deprecated methods)
On a woocommerce site the improvement of moving to flexbox would be unnoticeable. And the amount of custom work you have done to the site - i think you would have a hard time / lot of expense in making it work with flexbox.
Great if you are sure that performance wise there wont be a big difference, thats a relief actually!
One last question if i may! What kind of size reduction are we talking?
You can see here under the performance heading:
https://generatepress.com/generatepress-3-0-a-new-era/
On a standard kind of site the improvements are great. On a Woo site and the performance hit that makes you probably won't notice the difference.