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!
Google Plus provides loads of inspiration for front-end developers, especially when it comes to the CSS and JavaScript wonders they create. Last year I duplicated their incredible PhotoStack effect with both MooTools and pure CSS; this time I'm going to duplicate...
Client-side APIs on mobile and desktop devices are quickly providing the same APIs. Of course our mobile devices got access to some of these APIs first, but those APIs are slowly making their way to the desktop. One of those APIs is the getUserMedia API...
One thing I love doing is duplicating OS functionalities. One of the things your OS allows you to do easily is move from one item to another. Most of the time you're simply trying to get to the next or the previous item.
Warning: The demo for this post may brick your browser.
A while back I posted a MooTools plugin called dwProtector that aimed to make image theft more difficult -- NOT PREVENT IT COMPLETELY -- but make it more difficult for the rookie to average user...
Where do we add this php? I am a newbie
Brilliant, thank you!