Add display image to RSS feed in Wordpress

After spending hours and trying all the different functions and plugins, I would like to ask if one of you managed to add a new tag to your RSS feed for your favorite image.

With both the plugins and the features that I tried, the image got directly into the description tag, right in front of the description text, which I also need to extract.

Here is one of the features I tried:

function insertThumbnailRSS($content) { global $post; if ( has_post_thumbnail( $post->ID ) ){ $content = '' . get_the_post_thumbnail( $post->ID, 'thumbnail' ) . '' . $content; } return $content; } add_filter('the_excerpt_rss', 'insertThumbnailRSS'); add_filter('the_content_feed', 'insertThumbnailRSS'); 

Any ideas or suggestions?

I am retrieving the RSS feed of my blog using the Yahoo API.

Thanks for the help.

+5
source share
1 answer

This can be easily done by adding the following code to your functions.php file:

 function add_rss_item_image() { global $post; if(has_post_thumbnail($post->ID)) { $thumbnail = get_attachment_link(get_post_thumbnail_id($post->ID)); echo"\t<image>{$thumbnail}</image>\n"; } } add_action('rss2_item', 'add_rss_item_image'); add_action('rss_item', 'add_rss_item_image'); 

You can use the same method to output the value of a custom field in your feeds.

Good luck

0
source

Source: https://habr.com/ru/post/1237413/


All Articles