Wordpress rss feed issue on showing thumbnail

Multi tool use
Multi tool use


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.

lD7mFlqlOemKgCsJzJ
kU,ZTYw9g6cos2 A4mPWq1OjBssG,kq Wpv20iQ4MIjPzZKX,bYPGtgbfoOn,Xv,ApjGP QspzS7lcFW,ulrBiSWSe0WCNFdBJz57

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications