10 Handy WordPress RSS Feed Hacks

RSS is one of the primary delivery means for your blog’s content, your most loyal readers will likely access it via your RSS feed but despite this most people never give any thought to their RSS feed and how it displays. There are many enhancements and hacks you can make to your feed to provide extra features, earn extra income and help your readers spread your content. In this guide we’re going to look at some of the options open to you.

1. Display Post Thumbnails in the Feed

Lots of themes these days make use of post thumbnails or featured images but these aren’t included in your RSS feed by default. To add them in, add the following to your theme’s functions.php file.

[sourcecode language=”php”]
// show post thumbnails in feeds
function diw_post_thumbnail_feeds($content) {
global $post;
if(has_post_thumbnail($post->ID)) {
$content = ‘<div>’ . get_the_post_thumbnail($post->ID) . ‘</div>’ . $content;
return $content;
add_filter(‘the_excerpt_rss’, ‘diw_post_thumbnail_feeds’);
add_filter(‘the_content_feed’, ‘diw_post_thumbnail_feeds’);

Source: Digging into WordPress

2. Delay RSS Feed publishing

I seem to do this all the time (I did it on this very post!) you hit “Publish” instead of “Save Draft” or “Preview” on the post you are working on and have to hurridly edit it and put it back into draft status. Or you may notice some glaring error that needs correcting. What this snippet does is delay the updating of your RSS Feed, add the following to your theme’s functions.php file and it will be delayed by 5 minutes:

[sourcecode language=”php”]
* /**
* * puplish the content in the feed later
* * $where ist default-var in WordPress (wp-includes/query.php)
* * This function an a SQL-syntax
* */
* function publish_later_on_feed($where) {
* global $wpdb;
* if ( is_feed() ) {
* // timestamp in WP-format
* $now = gmdate(‘Y-m-d H:i:s’);
* // value for wait; + device
* $wait = ‘5’; // integer
* // https://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_timestampdiff
* // add SQL-sytax to default $where
* $where .= " AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, ‘$now’) > $wait ";
* }
* return $where;
* }
* add_filter(‘posts_where’, ‘publish_later_on_feed’);

Source : WP Engineer

3. Insert anything in to your RSS feed

You can use the following snippet to insert a link back to your site, some advertising, social media options etc. Basically anything you like, add the following to your theme’s functions.php file :

[sourcecode language=”php”]
function insertAds($content) {
$content = $content.’<hr /><a href="https://www.wprecipes.com">Have you visited WpRecipes today?</a><hr />’;
return $content;
add_filter(‘the_excerpt_rss’, ‘insertAds’);
add_filter(‘the_content_rss’, ‘insertAds’);


In this example, the custom html inserted is “<hr /><a href=”https://www.wprecipes.com”>Have you visited WpRecipes today?</a><hr />”
Simply change that to anything you like.

Source: WP Recipes

4. Exclude a category from your RSS feed

This is handy if you have a separate category for site news or something you wish to keep separate from your main feed. You will need to find the ID of the category you wish to exclude from your feed. To do this, in WordPress admin go to “Posts” > “Categories” and hover over the one you wish to know, look at your browser’s status bar for the url, at the end will be &tag_ID=10 where 10 is the category ID. Now add the following to your theme functions.php:

[sourcecode language=”php”]
function myFilter($query) {
if ($query-&amp;gt;is_feed) {
$query-&amp;gt;set(‘cat’,’10’); //Don’t forget to change the category ID =^o^=
return $query;



Source: WP Recipes

5. Create posts only for your RSS subscribers

If you would like to offer exclusive content that only RSS subscribers can see (maybe as an incentive to signup?) you need to create a category to house the posts. Find out the category ID like for the last hack and note it down. Then add this to theme’s functions.php :

[sourcecode language=”php”]
// show post thumbnails in feeds
function diw_post_thumbnail_feeds($content) {
global $post;
if(has_post_thumbnail($post-&amp;gt;ID)) {
$content = ‘&amp;lt;div&amp;gt;’ . get_the_post_thumbnail($post-&amp;gt;ID) . ‘&amp;lt;/div&amp;gt;’ . $content;
return $content;
add_filter(‘the_excerpt_rss’, ‘diw_post_thumbnail_feeds’);
add_filter(‘the_content_feed’, ‘diw_post_thumbnail_feeds’);

Now whenever you add a post to this category, it won’t show up on your blog’s homepage, category page, tag page or any other archive page but will be visible in your RSS Feed exclusively for your RSS subscribers.

Source: Web Developer Plus

6. Show any RSS Feed on your WordPress site

A handy piece of code that uses the WordPress feed parser to display any other RSS feed on your site. Handy to pull in forum feeds or a news feed etc, Just insert the following code into a theme file where you want it to appear :

[sourcecode language=”php”]
&amp;lt;?php include_once(ABSPATH . WPINC . ‘/rss.php’);
wp_rss(‘https://urlofthefeedhere.com/feed’, 3); ?&amp;gt;

Source: WP Recipes

7. Display your Average Feed Readers

If you are using Feedburner for your RSS feed you will notice that the public chiclet only displays yesterdays reader count, if you want to show the average over the last 7 days then this is what to do. Put the following in your theme’s functions.php file :

[sourcecode language=”php”]
function get_average_readers($feed_id,$interval = 7){
$today = date(‘Y-m-d’, strtotime(&amp;quot;now&amp;quot;));
$ago = date(‘Y-m-d’, strtotime(&amp;quot;-&amp;quot;.$interval.&amp;quot; days&amp;quot;));
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $feed_url);
$data = curl_exec($ch);
$xml = new SimpleXMLElement($data);
$fb = $xml-&amp;gt;feed-&amp;gt;entry[‘circulation’];

$nb = 0;
foreach($xml-&amp;gt;feed-&amp;gt;children() as $circ){
$nb += $circ[‘circulation’];

return round($nb/$interval);

Then paste the following where you want the count to appear in your theme, remember to replace wplift with your feed ID :

[sourcecode language=”php”]
$nb = get_average_readers(‘wplift’);
echo &amp;quot;I have &amp;quot;.$nb.&amp;quot; RSS readers&amp;quot;;

Source: Cats Who Blog

8. Separate RSS Feed for Custom Post types

If you’d like to link to a separate feed for a certain custom post type, use this code :

[sourcecode language=”php”]

You can also make a feed out of a custom post type and a taxonomy :

[sourcecode language=”php”]

Source: WP Beginner

9. Disable WordPress RSS Feeds completely

If you are creating a site which does not use RSS feeds and want to disable them, it’s pretty easy – just add the following to the theme’s functions.php file:

[sourcecode language=”php”]
* disable RSS feed
function wp_disable_feed() {
wp_die( __(‘Sorry, no feeds available, return to &amp;lt;a href=&amp;quot;’. get_bloginfo(‘url’) .’&amp;quot;&amp;gt;homepage&amp;lt;/a&amp;gt;’) );

add_action(‘do_feed’, ‘wp_disable_feed’, 1);
add_action(‘do_feed_rdf’, ‘wp_disable_feed’, 1);
add_action(‘do_feed_rss’, ‘wp_disable_feed’, 1);
add_action(‘do_feed_rss2’, ‘wp_disable_feed’, 1);
add_action(‘do_feed_atom’, ‘wp_disable_feed’, 1);

Source: Design Gala

10. Create your own user-defined RSS Feed

If you need a custom RSS feed, like for example, a feed indexing only somes categories + tags, or if you redirected all WordPress RSS feeds to Feedburner but still want to be able to get a category feed, the solution is to use a page template. Save the following code in a file called “custom-feed.php” and upload to your theme directory. Then create a new page in WordPress admin and save it blank and choose “custom-feed.php” as the template.

[sourcecode language=”php”]
Template Name: Custom Feed

$numposts = 5;

function yoast_rss_date( $timestamp = null ) {
$timestamp = ($timestamp==null) ? time() : $timestamp;
echo date(DATE_RSS, $timestamp);

function yoast_rss_text_limit($string, $length, $replacer = ‘…’) {
$string = strip_tags($string);
if(strlen($string) &amp;gt; $length)
return (preg_match(‘/^(.*)\W.*$/’, substr($string, 0, $length+1), $matches) ? $matches[1] : substr($string, 0, $length)) . $replacer;
return $string;

$posts = query_posts(‘showposts=’.$numposts);

$lastpost = $numposts – 1;

header(&amp;quot;Content-Type: application/rss+xml; charset=UTF-8&amp;quot;);
echo ‘&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;’;
?&amp;gt;&amp;lt;rss version=&amp;quot;2.0&amp;quot;&amp;gt;
&amp;lt;title&amp;gt;Yoast E-mail Update&amp;lt;/title&amp;gt;
&amp;lt;description&amp;gt;The latest blog posts from Yoast.com.&amp;lt;/description&amp;gt;
&amp;lt;pubDate&amp;gt;&amp;lt;?php yoast_rss_date( strtotime($ps[$lastpost]-&amp;gt;post_date_gmt) ); ?&amp;gt;&amp;lt;/pubDate&amp;gt;
&amp;lt;lastBuildDate&amp;gt;&amp;lt;?php yoast_rss_date( strtotime($ps[$lastpost]-&amp;gt;post_date_gmt) ); ?&amp;gt;&amp;lt;/lastBuildDate&amp;gt;
&amp;lt;managingEditor&amp;gt;[email protected]&amp;lt;/managingEditor&amp;gt;
&amp;lt;?php foreach ($posts as $post) { ?&amp;gt;
&amp;lt;title&amp;gt;&amp;lt;?php echo get_the_title($post-&amp;gt;ID); ?&amp;gt;&amp;lt;/title&amp;gt;
&amp;lt;link&amp;gt;&amp;lt;?php echo get_permalink($post-&amp;gt;ID); ?&amp;gt;&amp;lt;/link&amp;gt;
&amp;lt;description&amp;gt;&amp;lt;?php echo ‘&amp;lt;![CDATA[‘.yoast_rss_text_limit($post-&amp;gt;post_content, 500).’&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;Keep on reading: &amp;lt;a href=&amp;quot;’.get_permalink($post-&amp;gt;ID).’&amp;quot;&amp;gt;’.get_the_title($post-&amp;gt;ID).’&amp;lt;/a&amp;gt;’.’]]&amp;gt;’; ?&amp;gt;&amp;lt;/description&amp;gt;
&amp;lt;pubDate&amp;gt;&amp;lt;?php yoast_rss_date( strtotime($post-&amp;gt;post_date_gmt) ); ?&amp;gt;&amp;lt;/pubDate&amp;gt;
&amp;lt;guid&amp;gt;&amp;lt;?php echo get_permalink($post-&amp;gt;ID); ?&amp;gt;&amp;lt;/guid&amp;gt;
&amp;lt;?php } ?&amp;gt;

Source: Yoast



Oliver Dale is the founder of Kooc Media, An Internet Company based in Manchester, UK. I founded WPLift and ThemeFurnace, find out more on my Personal Blog. Thanks!

Related Articles


15 thoughts on “10 Handy WordPress RSS Feed Hacks”

  1. Have you noticed the first code for the images in feeds no longer works with 3.2?  Ever since upgrading to 3.2 the code no longer works where it used to prior.  Any ideas what may have changed?

  2. I want to use the weaver 2010 theme but can’t find RSS icon, don’t all themes have RSS and if not how do I add one?  Thanks

  3. how do I add
    tags to the content of the RSS? I need it because I’ve used the ”
    Display Post Thumbnails in the Feed” solution on my blog but now I need to customize the CSS on my magento site that reads the css and gives me a
    tag for the image but nothing for the text.

  4. How would you go about removing the date from the RSS feed?
    I run many of my posts without date in WP, but they still show up with date in the RSS feed. Any way to remove the date from the RSS?

  5. Quick correction: in #4, the need to add a minus sign before the category number, to EXCLUDE it, otherwise, that category will be the ONLY category to appear in your RSS feed:


  6. Hi!
    Great read… I was actually looking for something to fix a RSS problem!
    I use the RSS Image plugin to get images in my RSS
    I use Aweber’s blog-cast to send cool looking teaser to my lists, so they can read ;-)
    But somehow Aweber’s support pointed out that my image and content is in the tag and not in the tag??
    I saw the source code and it’s correct… I then checked out a brand new WP site I setup and it’s the same?
    Is this a new thing that everything get stuffed inside the tag ?? or how do I fix this issue?

    In advance: Thx


  7. Any one know how to add “4. EXCLUDE A CATEGORY FROM YOUR RSS FEED” I want to show only 1 category to this function below inc all detalis ?

    Thanks for help!

    add_action( ‘after_setup_theme’, ‘my_rss_template’ );
    * Register custom RSS template.
    function my_rss_template() {
    add_feed( ‘short’, ‘my_custom_rss_render’ );

    * Custom RSS template callback.
    function my_custom_rss_render() {
    get_template_part( ‘feed’, ‘short’ );

Comments are closed.


Create Your Own

Building beautiful WordPress websites has never been easier. Explore the visual drag & drop Theme Builder that does it all, and works on any theme. Coding skills needed: none.