Sometimes you may need to hide certain categories from your WordPress Blog. Currently there is no in-built facility available in WordPress to hide categories though there are many themes available to with this functionality. If your WordPress theme does not have this option, you will require making following changes to hide categories from your blog home page.

[1] Obtain category ID:

To obtain category ID, login to your WordPress admin and go to Posts > Categories. Click on the category name which you want to exclude from Home page. Copy the value of cat_ID from the URL.

categories.php?action=edit&cat_ID=XX

XX is your category ID.

[2]Add required code in theme’s functions.php:

Now, go to Appearance > Editor and open functions.php. Add the following function at the bottom:

function exclude_category($query) {
if ( $query->is_home ) {
$query->set('cat', '-xx');
}
return $query;
}
add_filter('pre_get_posts', 'exclude_category');

The above code must be written within php tag.

If you want to block multiple categories, use the following condition:

$query->set('cat', '-1 -2 -3 -4 -5');

Popularity: 26%

Post comment

You must be logged in to post a comment.

Enter your email address:




Wordpress Hosting

WordPress Premium Themes


WooThemes - Quality Themes, Great Support
WordPress Premium Themes by StudioPress
WordPress Themes by WPZOOM
Acosmin Premium Wordpress Themes
Professional WordPress Themes
NattyWP Premium WordPress Themes Club
Premium Wordpress Themes by Templatic
Frugal Themes
Solostream WordPress Themes
Solostream WordPress Themes

Categories

Tags

Business Wordpress theme e-commerce wordpress theme gallery wordpress theme online store using WordPress Personal Blog theme photography wordpress theme portfolio wordpress theme Real estate premium WordPress theme WooThemes Wordpress Business theme Wordpress e-commerce theme WordPress Magazine theme WordPress Micro blogging theme Wordpress Multimedia theme Wordpress NEWS theme Wordpress personal blog theme Wordpress Photoblog theme Wordpress Portfolio theme Wordpress travel blogging theme

RSS Web Hosting Discussion

RSS Affiliate Programs

Meta

WebHosting Talk