Wordpress rss feed issue on showing thumbnail


Wordpress rss feed issue on showing thumbnail



Below code not showing thumbnail from posts:


<?php
//grabs our post thumbnail image
function get_first_image_url($html) {
if (preg_match('/<img.+?src="(.+?)"/', $html, $matches)) {
return $matches[1];
}
}
?>



Below code not showing thumbnail from posts:


<span class="rss-image">
<?php echo '<img src="' . get_first_image_url($item -> get_content()) . '"/>'; ?>
</span>




1 Answer
1



Add this in functions.php


function get_first_image_url($fetch_image) {
global $fetch_image, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=['"]([^'"]+)['"].*>/i', $fetch_image, $matches);
$first_img = $matches [1] [0];

if(empty($first_img)){ //Defines a default image
$first_img = "/images/default.jpg";
}
return $first_img;
}



and use this


<span class="rss-image">
<?php echo '<img src="' . get_first_image_url($item -> get_content()) . '"/>'; ?>
</span>





Thanks bro.. but it did not working... still only title and content showing.. thumbnail not showing...
– user3305719
Jul 3 at 7:14






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

api-platform.com Unable to generate an IRI for the item of type

How to set up datasource with Spring for HikariCP?

PHP contact form sending but not receiving emails