Prevent Posts in a Category From Displaying in WordPress’ RSS Feed
I recently posted a snippet which prevented posts in a given category from displaying in WordPress' main loop. I even went on to create my first WordPress plugin to accomplish the task via the WordPress control panel. The one task those snippets doesn't complete is preventing posts from going into RSS feeds. Here's how you can prevent posts in a category from displaying in the RSS feed!
The PHP
The category check is done the same way the loop check was done:
function postsFilter($query) {
// Prevent from RSS feed
if($query->is_feed()) {
// No posts in category #11 may go into the feed
$query->set('cat', '-11');
}
}
add_action('pre_get_posts', 'postsFilter');
A pre_get_posts
filter is added to check for the is_feed() return value. If the value is true, we add the condition to remove the category form the final query. I have added this functionality to the WordPress plugin as well!
My team mate Edna Piranha is not only an awesome hacker; she's also a fantastic philosopher! Communication and online interactions is a subject that has kept her mind busy for a long time, and it has also resulted in a bunch of interesting experimental projects...
CSS and JavaScript: the lines seemingly get blurred by each browser release. They have always done a very different job but in the end they are both front-end technologies so they need do need to work closely. We have our .js files and our .css, but...
One major gripe that we've always had about CSS is that creating layouts seems to be more difficult than it should be. We have, of course, adapted and mastered the techniques for creating layouts, but there's no shaking the feeling that there should be a...
Backgrounds have become an integral part of creating a web 2.0-esque website since gradients have become all the rage. If you think gradient backgrounds are too cliche, maybe a fixed position background would work for you? It does provide a neat inherent effect by...
Where do we add this php? I am a newbie
Brilliant, thank you!