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!
CSS cubes really showcase what CSS has become over the years, evolving from simple color and dimension directives to a language capable of creating deep, creative visuals. Add animation and you've got something really neat. Unfortunately each CSS cube tutorial I've read is a bit...
Back in late 2012 it was not easy to find open source projects using requestAnimationFrame()
- this is the hook that allows Javascript code to synchronize with a web browser's native paint loop. Animations using this method can run at 60 fps and deliver fantastic...
Front-end developing is beautiful, and it's getting prettier by the day. Nowadays we got so many concepts, methodologies, good practices and whatnot to make our work stand out from the rest. Javascript (along with its countless third party libraries) and CSS have grown so big, helping...
Google Analytics is an outstanding website analytics tool that gives you way more information about your website than you probably need. Better to get more than you want than not enough, right? Anyways I check my website statistics more often than I should and...
Where do we add this php? I am a newbie
Brilliant, thank you!