-
AuthorPosts
-
January 4, 2019 at 9:34 am #1049912
Hello,
I know that you do not support WP-Rocket. But my question is only about getting a little piece of PHP-Code into the functions.php without error messages.The code is meant to fix the WP-Rocket-LazyLoad-Issue for a masonry gallery by applying WP-Rocket-LazyLoad to every image manually.
The given code is:
<?php $image = get_field( 'image' ); if( ! empty( $image ) && function_exists( 'get_rocket_option' ) && get_rocket_option( 'lazyload' ) && ! ( defined( 'DONOTROCKETOPTIMIZE' ) && DONOTROCKETOPTIMIZE ) ) : ?> <img src="data:image/gif;base64,R0lGODdhAQABAPAAAP///wAAACwAAAAAAQABAEACAkQBADs=" data-lazy-src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" /> <?php elseif( ! empty( $image ) ) : ?> <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" /> <?php endif; ?>
What the code is meant to do is also described here:
https://docs.wp-rocket.me/article/130-manually-apply-lazyload-to-an-image
How do I add this code to the functions.php within the following function:
function my_custom_code(){
…
}
add_action(‘wp_head’, ‘my_custom_code’);I would be very happy if you can help me.
Kind regards
Michael- This topic was modified 5 years, 10 months ago by elskeletto1.
January 5, 2019 at 6:01 am #1050202Hey elskeletto1,
Please try this in your functions.php file:
function elskeletto1_my_custom_code(){ $image = get_field( 'image' ); if( ! empty( $image ) && function_exists( 'get_rocket_option' ) && get_rocket_option( 'lazyload' ) && ! ( defined( 'DONOTROCKETOPTIMIZE' ) && DONOTROCKETOPTIMIZE ) ) : ?> <img src="data:image/gif;base64,R0lGODdhAQABAPAAAP///wAAACwAAAAAAQABAEACAkQBADs=" data-lazy-src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" /> <?php elseif( ! empty( $image ) ) : ?> <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" /> <?php endif; } add_action('wp_head', 'elskeletto1_my_custom_code');
Best regards,
Rikard- This reply was modified 5 years, 10 months ago by Rikard.
September 7, 2019 at 11:04 am #1135305The problem with the masonry element appears regardless of which lazyload plugin is used (I just tried the new Google “native lazyload” plugin)
Would it be possible to fix the lazyload / masonry issue in a future update of the theme? I’m sure that would be much appreciated by all your users.
September 8, 2019 at 4:12 am #1135549Hi lindenhof,
I’m not sure I understand your question, are you having problems with masonry? If so then where can we see the problem you are having?
Best regards,
RikardSeptember 9, 2019 at 1:57 pm #1136004The problem is that whenever I activate a “lazyload” plug-in (e.g. wprocket, or the new Google plug-in), which I would like to do for performance reasons, the “masonry” element stops working properly (images overlap). This appears to be a known bug as it has been described in multiple threads (for example the OP in this one). Would be great if your developer team could do something about it in a future update!
September 9, 2019 at 4:18 pm #1136105Hi lindenhof,
Yes, Enfold does not work well with the lazy loading yet, it will be fixed sometime in the future but we don’t know when for sure.
Best regards,
Victoria -
AuthorPosts
- You must be logged in to reply to this topic.