[Support request] Logo PNG not downsized – why?

Home Forums Support Logo PNG not downsized – why?

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #1405973
    Nic

    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)

    #1405979
    Nic

    i 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?

    #1406012
    Nic

    unfortunately you missed including a filter for function add_site_logo in class-hero $logo_url var! please fix this.

    #1406021
    Nic

    hot 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!

    #1406036
    David
    Staff
    Customer Support

    Hi there,

    why not simply upload a logo image of the required dimensions ? Thats is generally the standard practice.

    #1406079
    Nic

    just 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

    #1406086
    David
    Staff
    Customer Support

    I hear you 🙂
    Ill pass on your comments – thanks for sharing

    #1406139
    Nic

    just 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");
    #1406160
    Nic

    and 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");
    #1406460
    Tom
    Lead Developer
    Lead Developer

    Way too many filters when it comes to logos – need to figure out a way to connect them all.

    Thanks for sharing all your code! 🙂

    #1407205
    Nic

    i 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!

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.