• Resolved jorgitobg

    (@jorgitobg)


    Hi,

    I need to deactivate lazyloading from a HTML template generated by wordpress for html newsletters…. right now im using this:

    // DEACTIVATE Autoptimize
    add_filter(‘autoptimize_filter_noptimize’,’__return_true’);

    Is there some similar function to deactivate lazyloading? something like:

    // DEACTIVATE A3 LAZY LOAD
    add_filter( ‘a3_lazy_load_run_filter’, ‘__return_false’ );
    // DEACTIVATE WP-ROCKET LAZY LOAD
    add_filter( ‘do_rocket_lazyload’, ‘__return_false’ );

    Regards

Viewing 14 replies - 1 through 14 (of 14 total)
  • Thread Starter jorgitobg

    (@jorgitobg)

    I tried ?ao_noptimize=1 and then lazyloading is disabled… but with the old function lazyloading still working… any clue?

    https://hermandadblanca.org/boletin-semanal-novedades/?ao_noptimize=1

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    Hey @jorgitobg
    If the page is noptimized, lazyload should not be active on it either, but currently there is not a filter to disable lazyload specifically. I’ll add one for the next version though.

    Hope this helps,
    frank

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    OK, filter added in the GitHub version, if you want you can try it out immediately by downloading the zip here ??

    this will be part of Autoptimize 2.5.1 later.

    frank

    Thread Starter jorgitobg

    (@jorgitobg)

    I mod the but still not working….. any idea?

    // DEACTIVATE Autoptimize
    add_filter(‘autoptimize_filter_noptimize’,’__return_true’);
    add_filter(‘autoptimize_filter_imgopt_lazyload_js_noptimize’,’__return_false’);
    add_filter(‘autoptimize_filter_imgopt_should_lazyload’,’__return_true’);

    /**
    * Lazyload functions
    */
    public function should_lazyload() {
    if ( ! empty( $this->options[‘autoptimize_imgopt_checkbox_field_3’] ) ) {
    $lazyload_return = true;
    } else {
    $lazyload_return = false;
    }
    $lazyload_return = apply_filters( ‘autoptimize_filter_imgopt_should_lazyload’, $lazyload_return );

    return $lazyload_return;
    }

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    errr … where do you modify? can you post the full code you added/ changed?

    Thread Starter jorgitobg

    (@jorgitobg)

    wp-content/plugins/autoptimize/classes/autoptimizeImages.php

    I add this line “$lazyload_return = apply_filters( ‘autoptimize_filter_imgopt_should_lazyload’, $lazyload_return );”

    To

    /**
    * Lazyload functions
    */
    public function should_lazyload() {
    if ( ! empty( $this->options[‘autoptimize_imgopt_checkbox_field_3’] ) ) {
    $lazyload_return = true;
    } else {
    $lazyload_return = false;
    }
    $lazyload_return = apply_filters( ‘autoptimize_filter_imgopt_should_lazyload’, $lazyload_return );

    return $lazyload_return;
    }

    Thread Starter jorgitobg

    (@jorgitobg)

    I tried to upload autoptimize-master.zip but also didnt work….

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    no, you should not alter autoptimize like that (or any other plugin’s code for that matter); your changes would get lost with every plugin update. the goal of filters is to allow someone to change how wordpress core, theme or plugin works by having separate code that hooks into that filer.

    in this case you would use the filter in a code snippet much like this one;

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

    which will “false” should_lazyload if the URL contains “/my-newsletter” and in all other cases the return value will be “true” to allow images being lazyloaded.

    such code snippets can be added in different ways, but the easiest and safest manner is using the code snippets plugin.

    hope this helps ??
    frank

    Thread Starter jorgitobg

    (@jorgitobg)

    So I can not use this function on a single template? Something like:

    // DEACTIVATE Autoptimize
    add_filter(‘autoptimize_filter_noptimize’,’__return_true’);
    add_filter(‘autoptimize_filter_imgopt_should_lazyload’,’__return_false’);

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    add that code to the template’s PHP? haven’t done that myself yet, but I guess that could work ??

    doing both would be overkill though, one of those should be enough.

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    hmm, but based on e.g. https://stackoverflow.com/questions/4985162/how-can-i-use-add-filter-for-a-specific-page-template filters are not supposed to be used in a template file.

    Thread Starter jorgitobg

    (@jorgitobg)

    Long time ago Im using a lot of filters on single template pages to deactivate plugins:

    // DEACTIVATE A3 LAZY LOAD
    add_filter( ‘a3_lazy_load_run_filter’, ‘__return_false’ );
    // DEACTIVATE WP-ROCKET LAZY LOAD
    add_filter( ‘do_rocket_lazyload’, ‘__return_false’ );
    // DEACTIVATE Autoptimize
    add_filter(‘autoptimize_filter_noptimize’,’__return_true’);
    add_filter(‘autoptimize_filter_imgopt_lazyload_js_noptimize’,’__return_false’);
    add_filter(‘autoptimize_filter_imgopt_should_lazyload’,’__return_false’);
    // DEACTIVATE Lazy Loader
    add_filter(‘data-no-lazyload’,’__return_true’);
    add_filter(‘data-no-lazyload’,’__return_false’);
    add_filter( ‘lazy_load_responsive_images_inline_styles’, function () {
    return ”;
    } );

    This is more fast than using a filter for ALL pages. But for your plugin doesnt work.

    Your other solution works fine but Its another filter loading on ALL pages and I would prefer to not overload wordpress:

    add_filter(‘autoptimize_filter_imgopt_should_lazyload’,’jorgito_should_lazyload’,10,0);
    function jorgito_should_lazyload() {
    if ( strpos( $_SERVER[‘REQUEST_URI’], ‘/my-newsletter’) !== false ) {
    return false;
    } else {
    return true;
    }
    }

    Any idea?

    Regards

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    afraid not; given it works the “normal” way, the problem is specific to how filters get executed when in a template-file, which I suppose somehow gets triggered differently. could be a matter of order/ priority maybe? you could try embedding the filter in a function and hooking that function into WordPress’ init or plugins_loaded or template_redirect actions maybe to see if that changes anything?

    Thread Starter jorgitobg

    (@jorgitobg)

    Will try some options…

    Thanks for your support!

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Exclude lazy loading from a single html page’ is closed to new replies.