Support » Plugin: Autoptimize » Disable lazy loading on two specific pages

  • Resolved Selah

    (@tubescreamer)


    Hello, I have two pages with a masonry gallery and it’s being affected by the lazy loading setting in Autoptimize. The images end up overlapping the content that’s beneath it on mobile phones. How can I disable lazy loading on just those two specific pages as I can’t target it by image classes and it’ll be harder to target each individual image file?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter Selah

    (@tubescreamer)

    I already know how to disable lazy load for one URL/page, but how do I do it for two pages in the same filter?

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    The easiest solution; try 2.9 beta (download here) instead of 2.8.4, where you can enable an option to not lazyload (or optimize JS or optimize CSS or ..) on a per page/ post level? 🙂

    Thread Starter Selah

    (@tubescreamer)

    I can give that a try. Don’t consider me a pest, but what’s the hard way? (:

    • This reply was modified 1 month ago by Selah.
    Plugin Author Optimizing Matters

    (@optimizingmatters)

    adapting the code you mentioned to work on multiple pages 😀

    Thread Starter Selah

    (@tubescreamer)

    Nice. I have like 1 brain cell left, so figuring that out is going to be a fun time, lol.

    This is what I have so far:

    add_filter('autoptimize_filter_imgopt_should_lazyload','disable_lazyload_single_page',10,0);
    function disable_lazyload_single_page() {
    	if ( strpos( $_SERVER['REQUEST_URI'], '/slug-one') !== false ) {
    		return false;
    	} else {
    		return true;
    	}
    }

    That works for one of the pages, however, when I tried doing this to disable lazy load on the second page, it didn’t work:

    add_filter('autoptimize_filter_imgopt_should_lazyload','disable_lazyload_single_page',10,0);
    function disable_lazyload_single_page() {
    	if ((strpos( $_SERVER['REQUEST_URI'], '/slug-one') || strpos( $_SERVER['REQUEST_URI'], '/slug-two') !== false ) {
    		return false;
    	} else {
    		return true;
    	}
    }
    • This reply was modified 1 month ago by Selah.
    • This reply was modified 1 month ago by Selah.
    Plugin Author Optimizing Matters

    (@optimizingmatters)

    try changing

    if ((strpos( $_SERVER['REQUEST_URI'], '/slug-one') || strpos( $_SERVER['REQUEST_URI'], '/slug-two') !== false ) {

    into

    if ( strpos( $_SERVER['REQUEST_URI'], '/slug-one' ) !== false || strpos( $_SERVER['REQUEST_URI'], '/slug-two' ) !== false ) {

    maybe? 🙂

    Thread Starter Selah

    (@tubescreamer)

    See I told you I had like one brain cell left. That makes a lot more sense and it works.

    Thanks you! Much appreciated. 🙂

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    you’re welcome, feel free to leave a review of the plugin and support here! 🙂

    Thread Starter Selah

    (@tubescreamer)

    Done!

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