[Support request] How to add extra attributes to logo img tag

Home Forums Support [Support request] How to add extra attributes to logo img tag

Home Forums Support How to add extra attributes to logo img tag

Viewing 15 posts - 1 through 15 (of 22 total)
  • Author
    Posts
  • #1184294
    Azman

    I am using a CDN to optimize and serve my images. And it compresses all the images on my website. It even compresses the logo, which I don’t want to compress.

    So, to avoid this they asked me to add this attribute to the logo image tag: data-gumlet=”false”

    And I have no clue on how to do it. Please help.

    #1184481
    David
    Staff
    Customer Support

    Hi there,

    try adding this PHP Snippet:

    add_filter( 'generate_navigation_logo_output', function() {
        return sprintf(
            '<div class="site-logo sticky-logo navigation-logo">
                <a href="%1$s" title="%2$s" rel="home">
                    <img data-gumlet="false" src="%3$s" alt="%4$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_navigation_logo', $settings['sticky_menu_logo'] ) ),
            esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) )
        );
    } );
    #1184544
    Azman

    Thanks David, but how and where to add this PHP script?

    #1184546
    David
    Staff
    Customer Support
    #1185467
    Azman

    I added the script using the Code Snippet plugin, but the logo is still getting compressed.

    #1185581
    David
    Staff
    Customer Support

    How did you add the code ?
    If you have removed it can you re-add it.

    #1185623
    Azman

    I have added it using Code Snippet plugin, and it is still live with “Run Snippet Everywhere” enabled.

    #1185641
    David
    Staff
    Customer Support

    Try this snippet instead:

    add_filter( 'generate_logo_output', 'tu_logo_class', 10, 3 );
    function tu_logo_class( $output, $logo_url, $html_attr ) {
    	printf(
    		'<div class="navigation-branding">
    			<div class="site-logo">
    				<a href="%1$s" title="%2$s" rel="home">
    					<img data-gumlet="false" data-gmlazy="false" %3$s />
    				</a>
    			</div>
    		</div>',
    		esc_url( apply_filters( 'generate_logo_href' , home_url( '/' ) ) ),
    		esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) ),
    		$html_attr
    	);
    }

    It may require some CSS for sizing – so add the code and let know.

    #1185650
    Azman

    Done that! Yes, now it needs CSS. Please look into it.

    #1185732
    David
    Staff
    Customer Support

    Add this CSS:

    .site-logo img {
        max-width: 200px;
    }
    #1185784
    Azman

    David, it’s good now, but it break the order of navigation menu, I guess.
    Checkout by clicking on one of the blog post and scroll.

    By the way, you helped me achieve that navigation – https://generatepress.com/forums/topic/redesigned-header-navigation-like-verywellfit/

    #1185792
    David
    Staff
    Customer Support

    I made an edit to this code

    #1185973
    Azman

    Now again it is getting served by the CDN.

    #1185978
    David
    Staff
    Customer Support

    Oops – made another change.

    #1186081
    Azman

    Now the logo goes completely missing…

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