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: 20%

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


RSS Web Hosting Discussion

RSS Affiliate Programs

Meta