• Resolved Rado

    (@jeriksson)


    Hi,

    I have a site that’s using autopost thumbnails pro which grabs the first image of post and makes it the featured image to display on the front page for posts.

    The code that becomes like this:

    <a href="http://mydomain/xdev/2014/07/30/thispost/" title="thispost"><img src="http://mydomain/xdev/wp-content/uploads/freshizer/a6b809faa654654484cefe28f_thispostjpg" alt="thispost"></a>

    Why won’t bj lazyload detect this code as an image and lazyload it? Is it an regex issue? Lazyload works perfectly on the actual posts (singles)

    https://wordpress.org/plugins/bj-lazy-load/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Rado

    (@jeriksson)

    ok pretty sure i found the issue, the images grabbed for the front page are not actually within the $get_the_content , they are being put outside, does this matter?

    i tried to add style=”display: inline;” class=”lazy data-lazy-ready” to all the front page images to see if the plugin would detect them then as it seems to add this code for the single pages but that didn’t work either, ideas welcome!

    Plugin Author bjornjohansen

    (@bjornjohansen)

    Run the code through the filter “bj_lazy_load_html” as explained here: https://wordpress.org/plugins/bj-lazy-load/other_notes/

    Thread Starter Rado

    (@jeriksson)

    sorry i’m not very good with php, can you explain why this code won’t work

    echo $img_html= '<a href="'; the_permalink(); echo '">'; echo '<img src="'; echo catch_that_image(); echo '" alt="'; the_title(); echo '"></a>';
    $img_html = apply_filters( 'bj_lazy_load_html', $img_html );
    echo $img_html;
    }

    catch_that_image does bring back the full url of feature image if available otherwise replace it with a static one:

    function catch_that_image() {
      global $post, $posts;
      $first_img = '';
      ob_start();
      ob_end_clean();
    
      if( $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches) )
    {
    $first_img = $matches[1][0];
    }
    
      if(empty($first_img)) {
        $first_img = "/staff.png";
      }
      return $first_img;
    }

    It’s probably something broken in my first code!

    Thread Starter Rado

    (@jeriksson)

    i need to learn how to mix php and html, i usually can do it but in this case i’m already inside an if statement not sure if that matters, but this will not render:

    <?php if ( get_the_post_thumbnail($post_id) != '' ) {
    
    		$img_html= ?><a href="<?php the_permalink(); ?> <img src="<?php catch_that_image(); ?>" alt="<?php the_title(); ?>"></a><?php ;
    		$img_html = apply_filters( 'bj_lazy_load_html', $img_html );
    		echo $img_html;
    		}

    any help appreciated 🙂

    Thread Starter Rado

    (@jeriksson)

    solved !

    $img_html = '<a href="' . get_permalink() . '" title="' . get_the_title() . '"><img src="' . catch_that_image() . '" alt="' . get_the_title() . '"></a>';
    		 $img_html = apply_filters( 'bj_lazy_load_html', $img_html );
    		 echo $img_html;
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Front page images not being lazyloaded’ is closed to new replies.