Create Post Only For Your RSS Subscribers in WordPress

To benefit their regular readers, blog owners some times need to create posts only for those who subscribe to their RSS Feed. The benefit might be some promotional scheme, freebies or discount announcement that you only want to provide to your regular RSS subscribers. Here's how to do it if you have a WordPress powered blog.

1. First of all, you need to define a category specifically for posts that are to be displayed only in RSS Feed. Let’s say you define a new category RSS Only to handle RSS only posts.

After defining the category note down its category ID. To know category ID of the category, open the edit category page for that category and in the address bar of the page, you can find category ID.

2. Now open your theme's functions.php file in an editor or use the theme editor in WordPress admin. If your theme does not have functions.php file, create one. Add the following code to your functions.php file.

<?php
function excludeCategory($query)
{
	if($query->is_home | $query->is_archive )
	$query->set('cat','-3');
	return $query;
}
add_filter('pre_get_posts', 'excludeCategory'); 
?>

pre_get_posts is a WordPress filter which is run before fetching posts from the database. What we've done here is to exclude the category defined above from all pages except RSS Feed. Remember to use the negative sign before category ID to exclude that category.

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.

The post page would however be there as it is for every other post but the post won't show up anywhere else on your blog.

3. And lastly, if you are using wp_list_categories function to display categories list somewhere in your theme, you need to pass a parameter to wp_list_categories to exclude category meant only for RSS feeds from displaying.

wp_list_categories('exclude=3');

And if wp_list_categories already has parameters then append the exclude parameter using & sign.

wp_list_categories('show_count=1&exclude=3');

Now you can create special posts meant only for your RSS readers. If you know or use some other method of creating RSS only posts, feel free to share them in comments below.

About LEWIS OGDEN

Lewis is the founder of WP Loaded, a passionate entrepreneur with a passion for online business and a curiosity for all things WordPress.