- This topic has 10 replies, 3 voices, and was last updated 3 years, 8 months ago by Nic.
-
AuthorPosts
-
August 17, 2020 at 4:43 am #1405973Nic
I’ve noticed that my uploaded logo through customizer is not downsized. It’s loaded in full size (1400×300) and i wonder why. After uploading and selecting the image as the logo, i get prompted to crop the image. i tried both. cropping and skipping. in both variants image remains very large (and gets downsized through css). is this the regular behavior of GBP?
WP 5.4.2, GB Version 1.1.2 and GPP Version 1.11.2 and GP Theme 2.4.2.
i hooked in filter generate_logo_output to see whats going on and from that point i see that there is no true resizing:
<div class="site-logo"> <a href="http://localhost/unitels/" title="UNITELS" rel="home"> <img class="header-image" alt="UNITELS" src="http://localhost/unitels/wp-content/uploads/2020/08/LOGO_unitels_2020.png" title="UNITELS" srcset="http://localhost/unitels/wp-content/uploads/2020/08/LOGO_unitels_2020.png 1x, http://localhost/unitels/wp-content/uploads/2020/08/LOGO_unitels_2020.png 2x" width="1389" height="334" /> </a> </div>
i would expect at least default images sizes from wordpress (thumbnail/medium/large)
August 17, 2020 at 4:48 am #1405979Nici managed to write a custom filter for this. this will output a true downsized (medium) image. copy and paste it into your functions.php
function check_logo_img(){ $logo_url = ( function_exists( 'the_custom_logo' ) && get_theme_mod( 'custom_logo' ) ) ? wp_get_attachment_image_src( get_theme_mod( 'custom_logo' ), 'medium' ) : false; $logo_url = ( $logo_url ) ? $logo_url[0] : generate_get_option( 'logo' ); return $logo_url; } add_filter("generate_logo","check_logo_img");
i this really neccessary?
August 17, 2020 at 5:20 am #1406012Nicunfortunately you missed including a filter for function add_site_logo in class-hero $logo_url var! please fix this.
August 17, 2020 at 5:28 am #1406021Nichot fix for global header element block in case you use it:
function check_logo_retina_img($args){ $args["src"] = get_the_post_thumbnail_url( 1355,"medium" ); return $args; } add_filter("generate_page_hero_logo_attributes","check_logo_retina_img");
change 1355 to corresponding id of your element block post id!
August 17, 2020 at 5:34 am #1406036DavidStaffCustomer SupportHi there,
why not simply upload a logo image of the required dimensions ? Thats is generally the standard practice.
August 17, 2020 at 6:07 am #1406079Nicjust one of a few things i take into account when working with a lot of clients… you have to be prepared for everything 😉 but seems i missed nothing and my workaround seems legit
August 17, 2020 at 6:14 am #1406086DavidStaffCustomer SupportI hear you 🙂
Ill pass on your comments – thanks for sharingAugust 17, 2020 at 6:48 am #1406139Nicjust for everyone stumbling over this, there is also a mobile header img filter:
// mobile header logo; function check_logoimg_in_mobile_header($imgurl){ $settings = wp_parse_args( get_option( 'generate_menu_plus_settings') ); if(!empty($settings["mobile_header_logo"])){ $logoid = attachment_url_to_postid($settings["mobile_header_logo"]); $logo = wp_get_attachment_image_src( $logoid, 'medium' ); if(isset($logo[0])) return $logo[0]; } return $imgurl; } add_filter("generate_mobile_header_logo","check_logoimg_in_mobile_header");
August 17, 2020 at 7:03 am #1406160Nicand one more for sticky menu logo (jesus!)
function check_sticky_nav_logo($output){ $settings = wp_parse_args( get_option( 'generate_menu_plus_settings') ); if(!empty($settings["sticky_navigation_logo"])){ $logoid = attachment_url_to_postid($settings["sticky_navigation_logo"]); $logo = wp_get_attachment_image_src( $logoid, 'medium' ); if(isset($logo[0])) { $output = sprintf( '<div class="sticky-navigation-logo"> <a href="%1$s" title="%2$s" rel="home"> <img 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( $logo[0] ) ); } } return $output; } add_filter("generate_sticky_navigation_logo_output","check_sticky_nav_logo");
August 17, 2020 at 8:39 am #1406460TomLead DeveloperLead DeveloperWay too many filters when it comes to logos – need to figure out a way to connect them all.
Thanks for sharing all your code! 🙂
August 18, 2020 at 12:10 am #1407205Nici am glad that there is are kind of wrapping filters all around so i got this issue covered – more or less. but indeed it would be way easier with ONE filter for the logo image size only. something like
$logo_url = ( function_exists( 'the_custom_logo' ) && get_theme_mod( 'custom_logo' ) ) ? wp_get_attachment_image_src( get_theme_mod( 'custom_logo' ), apply_filter('generate_logo_img_src_size','medium') ) : false;
thanks in advance!
-
AuthorPosts
- You must be logged in to reply to this topic.