Lazy Loading Fix for WP Rocket
-
This is not a problem post but rather a solution. I just downloaded this amazing plugin and came across an issue where the force inline SVG option wasn’t working because I was lazy loading my images. I also use Divi, so forcing inline svg images for me is a must. I also use Lazy Load by WP Rocket (not WP Rocket itself) and I found this webpage by them: https://docs.wp-rocket.me/article/15-disabling-lazy-load-on-specific-images
I ended up adding this to me child theme’s functions.php file:
function rocket_lazyload_exclude_src( $src ) {
$src[] = ‘svg’;return $src;
}
add_filter( ‘rocket_lazyload_excluded_src’, ‘rocket_lazyload_exclude_src’ );What this code is going to do is take any image you have that has “svg” inside it’s filename, whether that be logo-svg.jpg or in this case logo.svg and the Lazy Loading for that image will be skipped, allowing SVG-Support to do its work and force the SVG to be inline.
Usually SVG files are really small if it’s a simple logo, so you don’t have to really worry about Lazy Loading SVG files anyways.
I hope this fix finds someone and helps save some time! 🙂
- The topic ‘Lazy Loading Fix for WP Rocket’ is closed to new replies.