Snippet: A "Feed Only" Shortcode for WordPress

This might be valuable for banner ads, pitches to get people on to your website rather than simply reading stuff in their RSS feeds. You can address your RSS subscribers differently in each and every post, just by using this WordPress shortcode trick!

I’m not and ad-guy myself and I don’t care much if people read my feed or browse my website, as long as they’re reading my content. But I do know that some of you own websites that are driven by adverts and that’s good. Giving not full content but excerpts in your RSS feeds is one way to solve the problem, but that annoys most people including myself.

With this shortcode trick, you’ll be able to squeeze content into your posts that will be displayed in your feeds only. And by extending this example with a few extra lines, you’ll be able to do the same thing but the other way round — hide certain parts of your content in your RSS feed. Combining the two you might be able to give the full post content, where for instance the download link is visible to people on your website, while people reading your RSS feed get a different message, like “download available from this website”.

On to the code (for functions.php)!

function feedonly_shortcode( $atts, $content = null) {
	if (!is_feed()) return "";
	return $content;
add_shortcode('feedonly', 'feedonly_shortcode');

Once that is done, go ahead and create a new post, write some content, and then add:

... some content ...
[feedonly]Dear RSS readers, I'd really appreciate if you you came to <a href="">my website</a> and clicked a few banner ads ;)[/feedonly]

When you publish that you won’t see the text between the feedonly short codes on your website, but you will if you open up your RSS feed.

I believe this is a more intelligent and interactive way to speak to your RSS subscribers, rather than just sticking banners at the top/bottom of each feed entry, which don’t get clicked anyway ;) Hope this gets you closer to your feed readers, and please don’t annoy them too much ;)

Thank you for reading!

5 thoughts on “Snippet: A "Feed Only" Shortcode for WordPress

  1. Tweets that mention Snippet: A “Feed Only” Shortcode for WordPress --

  2. Great snippet Konstantin! Another use I thought of might be asking people to "subscribe to your feed", such a message would be irrelevant to people that are reading your feed :) Thanks!

Comments are closed.