Home/ Journal Bens Projects Binary Moon Archives About Ben Gillbanks Subscribe to Binary Moon Updates

Subscribe to Binary Moon Website Updates, it's Free and Easy to Stay in Touch

Search Binary Moon

Search Binary Moon

An Intro to WordPress Filters: How to Add Custom Stuff to your RSS Feed

Recently I have added some custom content to the RSS feeds on 2 of my websites.

Here on Binary Moon I have added a notice that tells people if a specific post is in the Art Directed category, so they know to visit my site to see something styled a bit differently, and over on WPVote I added an automatically generated thumbnail to show a screenshot of the website that has been written about. Check out the WPVote feed to see what I mean.

Both of these things are an excellent way to engage people more with the content, and there is no limit to what you could do. For example you could use this very simple code to:

  • Link to your Twitter account and other social networking or social bookmarking accounts
  • Add a copyright notice to your feed
  • list related posts or other posts in the same category
  • Promote other websites you own
  • Sell advertising to people - particularly valuable if you have a large RSS subscriber list

The code to do this is really simple as well. It makes use of the filter system that is integrated into WordPress to hook into the content, make some changes, and then output it again with the new additions.

Using a filter is easy, you just have to add some simple code to the functions.php file found in your theme. The basic usage looks like this:

function contentModifier ($contentToFilter) {
// do stuff with content
return $contentToFilter;
}

add_filter('filterName', 'contentModifier ');

There are actually loads and loads of filters available, and there's a list of all the WordPress filters on the Codex. Many theme frameworks also add their own custom filters such as Elemental has around 33 of them (listed on the Elemental theme documentation), which allows you to change the theme without touching the code.

To add custom stuff to my RSS feeds I made use of 2 filters, that both used the same modification function. The filters are called the_excerpt_rss and the_content_rss. When the filter is executed the data to be modified is passed to the function you specify. The content can then be altered however you wish and returned.

In this example I am going to link to my Twitter page at the bottom of the content:

function bm_rssContent($content) {
	$content = $content . '<p>Like my blog? Why don't you <a href="http://twitter.com/binarymoon/">follow me on Twitter</a></p>';
	return $content;
}
add_filter('the_excerpt_rss', 'bm_rssContent');
add_filter('the_content_rss', 'bm_rssContent');

So what would you use something like this for? I bet you have lots of idea that I haven't considered.

15 Responses to “An Intro to WordPress Filters: How to Add Custom Stuff to your RSS Feed” Leave a reply ›

Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

About me

About BenMy name is Ben Gillbanks. I'm a lover of Video Games, WordPress, Web Development and everything in between.

I have been working on the internet since 1998, and working with computers even longer. I am a hardcore Nintendo fanboy and have owned most of their consoles at one stage or another.

Read more about me on my about page.


Follow Me


Random Link-outs

The Binary Network links to all my websites
bengillbanks.co.uk - Ben Gillbanks

Ben Gillbanks

All my websites under 1 roof, the easiest way to find out what I do

Pro Theme Design - premium WordPress themes

Pro Theme Design

Premium WordPress themes by web design pros (erm... that includes me)

Binary Joy - gaming news and reviews

Binary Joy

Gaming news and reviews

Binary Sun - play free online games

Binary Sun

Play and download free and paid games (many made by me)

Gaming Angel - download and play games online

Gaming Angel

Stacks of shareware games, free to try and cheap to buy