Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #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, 11 months ago by elskeletto1.
    #1050202

    Hey 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, 11 months ago by Rikard.
    #1135305

    The 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.

    #1135549

    Hi 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,
    Rikard

    #1136004

    The 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!

    #1136105

    Hi 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

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.