I am using a WordPress RSS to use in my iOS project. The feed doesn’t have thumbnail links in it, so I searched and found this code to add thumbnail links to feed.
/* include thumbnail in RSS feed */
function add_thumb_to_RSS($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', 'add_thumb_to_RSS');
add_filter('the_content_feed', 'add_thumb_to_RSS')
This code adds the image link in feed, but it adds as html code in the beginning of description tag like this:
<description>
<![CDATA[
<img width="150" height="150" src="http://www.ipadia.co/wp-content/uploads/2012/02/sayfada-bul-150x150.png" class="attachment-thumbnail wp-post-image" alt="sayfada bul" title="sayfada bul" />Some text some text Some text some text Some text some text Some text some text Some text some text Some text some text ....
]]>
</description>
I want to add image link with another tag like <image>
or <thumb> the link </thumb>
. So I can parse this more easily.
How can I do this? Thanks in advance.
I solved it finally 🙂 I changed the function that I posted before. The new function is this:
This gives the image link in new tag
<post-thumbnail>
like I wanted.There are 2 functions in wordpress that can help you in a very easy way, try this:
Edit:
To modify the feed you can check this documentation
One easy option is modifying directly the feed template, an example:
in file wp-includes/feed-rss2.php (note you may modify another feed template as “feed-rss.php”, “feed-atom.php”) you can add the new tag:
There is a plugin to do this for WordPress that adds the image as an enclosure.
https://github.com/kasparsd/feed-image-enclosure/blob/master/feed-image-enclosure.php