• Hi,

    I would like to request that you add loading=”lazy” as an option for images displayed by the plugin. Google Pagespeed Insights complain that these images aren’t loading lazy.

    Also, where can I add loading=”lazy” in the plugin files for images? I would like to add it now.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter drumstick

    (@drumstick)

    I would also like to add that I like your plugin very much!

    Plugin Author Ajay

    (@ajay)

    I have added this as a new feature to be implemented in the next major version.

    https://github.com/WebberZone/contextual-related-posts/issues/125

    Not tested, but try this in your theme’s functions.php

    
    function crp_ll_attr( $attr ) {
    $attr['loading'] => 'lazy';
    return $attr;
    }
    add_filter( 'crp_get_image_attributes', 'crp_ll_attr' );
    
    
    Thread Starter drumstick

    (@drumstick)

    Thanks,

    I do get this error when trying to add it to code snippets.

    Parse Error : syntax error, unexpected ‘=>’ (T_DOUBLE_ARROW), expecting ‘;’ on line 2
    Parse Error : syntax error, unexpected ‘=>’ (T_DOUBLE_ARROW) on line 2
    Parse Error : syntax error, unexpected ”lazy” (T_CONSTANT_ENCAPSED_STRING), expecting ‘;’ on line 2

    Thread Starter drumstick

    (@drumstick)

    I tried the code but replaced => with =, but it didn’t show up in the img-tag.

    Plugin Author Ajay

    (@ajay)

    My apologies, it had to be a = not the =>

    I tried the code and it does work on my test install. Where are you putting the code?

    One good place to put it in wp-content/mu-plugins/ – You can create a new php file e.g. crp-function.php

    
    /**
     * Add lazyloading attribute.
     *
     * @param array $attr Attributes array.
     * @return array Updated attributes array.
     */
    function crp_ll_attr( $attr ) {
    	$attr['loading'] = 'lazy';
    	return $attr;
    }
    add_filter( 'crp_get_image_attributes', 'crp_ll_attr' );
    
    
    Thread Starter drumstick

    (@drumstick)

    I put it in the Code Snippets plugin as a new snippet.

    Plugin Author Ajay

    (@ajay)

    That should work in theory, but am not sure when that steps in. Worth trying it with your theme’s functions.php or mu-plugins as above

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘loading lazy’ is closed to new replies.