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