Site logo

Archived topic

Lazyload images and Logo issue

7 replies · Started by Kevin Wabiszewski on January 5, 2020

Viewing posts 1–8 of 8

Hello, I am currently using WP Rocket to lazyload images, but when I enable this option it causes the menu icon on mobile to fall below the logo and search icon.

The issue only seems to happen on phones. I was wondering if there is a fix to this using CSS or some other method with Generate Press?

I believe this is the CSS in my theme related to the header formatting on mobile:

.main-navigation {
border-bottom: 2px #ba1f1f solid;
}

.post-template-default .widget_search {
margin-top: 51px;
}

@media (max-width: 768px) {
#mobile-header {
background-color: #ffffff;
}
.main-navigation .main-nav ul li a {
background-color: #3f3f3f;
}
button.menu-toggle {
color: #000000;
}
}

button.menu-toggle:hover,
button.menu-toggle:focus,
.main-navigation .mobile-bar-items a,
.main-navigation .mobile-bar-items a:hover,
.main-navigation .mobile-bar-items a:focus {
color: #000;
}

Thanks for your help/time

Thanks for getting back to me, David. Since it is the three lines and the word menu button that fall below the logo when lazyload is enabled with mobile, do you think it's an issue with the logo lazyloading or the image used to generate the 3 lines next to the word menu?

Can I used the snippets plugin to do the second option they recommend? "Disabling LazyLoad on an image class"

What do you recommend?

It's most likely the logo - the three lines/text aren't images.

The mobile header logo doesn't have a specific class, but we can tell WPRocket not to lazy load it with a filter:

add_filter( 'generate_mobile_header_logo_output', function( $output ) {
    if ( ! function_exists( 'generate_menu_plus_get_defaults' ) ) {
        return $output;
    }

    $settings = wp_parse_args(
        get_option( 'generate_menu_plus_settings', array() ),
        generate_menu_plus_get_defaults()
    );

    return sprintf(
        '<div class="site-logo mobile-header-logo">
            <a href="%1$s" title="%2$s" rel="home">
                <img src="%3$s" data-no-lazy="1" 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_mobile_header_logo', $settings['mobile_header_logo'] ) ),
        esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) )
    );
} );

Adding PHP: https://docs.generatepress.com/article/adding-php/

That's exactly what I needed Tom. Thanks so much!

You're welcome :)

Hey Tom,
I have the same problem but for both, mobile and desktop versions.
Tried this code but getting this error

"This is the largest contentful element painted within the viewport. Learn More
<img src="https://mywebsite.com/logo.png" data-no-lazy="1" alt="Website Logo">"

Is there any solution for both mobile and desktop?

Thank you

Hi there,

can you raise a new topic where you can privately share your site URL and we can take a look

This archived topic is closed to new replies.