How to include the image in your WordPress RSS feed

 

Cut the queue if you know how.

WordPress is a great open source project for blogging and content management. Millions of users use it everyday. RSS (Really Simple Syndication) feed is a very commonly used feature among bloggers to broadcast latest posts and updates.

Unfortunately, the default WordPress RSS does not include any media items. Some bloggers said the image URL will be included if you choose Full Text under Settings—Reading–For each article in a feed, show. Unfortunately this is not true for the default templates (Twentyten or Twentyeleven).

There are different ways to include images in the RSS feed. You can directly modify the feed-rss2.php under wp-includes directory.

The safer way to modify the default RSS feed behavior is through your template. This will avoid some possible issues in future upgrade. So, here is how to put the URL of the first image in your RSS feed.

Corresponding to your theme (template), there is a file named functions.php, in which most template related functions (e.g., rendering comments) are placed. So, you can open this file with any text editor (e.g., Notepad++), and scroll all the way to the end, and put the following code:
function add_image_into_rss_feeds($content) {
global $post, $posts;
$img_url_to_be_inserted = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$img_url_to_be_inserted = $matches [1] [0];
if(!empty($img_url_to_be_inserted)){
$content = '<img src="' . $img_url_to_be_inserted . '">' . $content;
}
return $content;
}
// if you want to include image when using excerts, uncomment the following line
// add_filter('the_excerpt_rss', 'add_image_into_rss_feeds');
add_filter('the_content_feed', 'add_image_into_rss_feeds');

Now, add a new post with an image, then generate the new RSS feed. You images should show up properly. A working example is a funny picture blog. You may check the feed here: http://feeds.feedburner.com/JokeslabMedia

Simon

Simon is a freelancer on web design, internet marketing, web hosting, and programming.In last 10 years, he has worked with thousands webmasters to improve their internet marketing strategies and improve their websites as well. He is working for: Funny Portal . He likes reading, reading, and reading...... You can catch him at: Google+ .

View Comments

Share
Published by
Simon

Recent Posts

How to connect to PPTP VPN server from a Windows machine (Windows 7 as an example)

For some reasons, you may need use VPN service. If you do not have a…

10 years ago

How to install your own VPN server in 5 mins (PPTP on CentOS, RedHat and Ubuntu)

Virtual Private Network (VPN) is the most effective way to bypass access control, the censorship,…

12 years ago

How to create a 404 page?

404 page can be your invisible cash cow!. As I mentioned in the previous post…

13 years ago

How to use popup ads wisely?

Some consultants may tell you as a free hosting provider, you should stay away from…

13 years ago

5 rules to find a perfect domain name for your free hosting service

Most people believes that a good domain can attract and retain users for your free…

13 years ago