Site logo

Archived topic

How to add extra attributes to logo img tag

21 replies · Started by Azman on March 3, 2020

Viewing posts 1–15 of 22

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.

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' ) ) )
    );
} );

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

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

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

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

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.

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

Add this CSS:

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

Now again it is getting served by the CDN.

Oops - made another change.

Now the logo goes completely missing...

This archived topic is closed to new replies.