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!
With CSS border-radius, I showed you how CSS can bridge the gap between design and development by adding rounded corners to elements. CSS gradients are another step in that direction. Now that CSS gradients are supported in Internet Explorer 8+, Firefox, Safari, and Chrome...
Sooner or later you'll run across a regular expression. With their cryptic syntax, confusing documentation and massive learning curve, most developers settle for copying and pasting them from StackOverflow and hoping they work. But what if you could decode regular expressions and harness their power? In...
A long time back I coded a MooTools class called OpenLinks. The class is quite useful but the code...sucks. I've gotten much better with MooTools over the past years so I thought I'd go back and update the class to be better, faster...
One of the more impressive MooTools plugins to hit the Forge recently was The Wall by Marco Dell'Anna. The Wall creates an endless grid of elements which can be grabbed and dragged, fading in elements as they are encountered. Let me show...
Where do we add this php? I am a newbie
Brilliant, thank you!