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');
More From wppremium
- How to import your blog from LiveJournal to WordPress blog
- How to reset your WordPress admin password?
- Import Movable Type or TypePad blog to WordPress blog
wppremium Recommends
Popularity: 20%
WordPress Premium Themes
Categories
Tags
Web Hosting Discussion
- RatePoint Accounts Permanently Closing on February 02, 2012
- Error when trying to upgrade SMF 1.1.15 to 1.1.16
- Web Application Gallery module is unavailable
- What is Black Hat SEO and does it affect my website ranking?
- How to optimize MySQL database using phpMyAdmin
- How to repair a corrupted MySQL database from cPanel and phpMyAdmin
- How to change the database storage engine of a MySQL database table
Affiliate Programs
- 1BodyCare Affiliate Program
- ElegantThemes Affiliate Program
- Templatic.com Affiliate Program – Premium WordPress Themes provider
- PayPal Affiliate Program
- wpremix affiliate program – WordPress Premium themes provider
- Web Hosting Affiliate – DedicatedNOW Affiliate Program
- WooThemes Affiliate Program










