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