Search
Close this search box.

How to Hide Category from WordPress Blog Page

By default, the WordPress blog shows all posts from all categories. But in some situations, you want to exclude posts from a specific category.

To hide the category from the WordPress blog page we need to modify the WordPress loop.  We will modify the loop by using the pre_get_posts hook.

Add the following code snippet in your themes functions.php file. Replace category ids with the category id want to exclude.

function hide_category_blog( $query ) {
if ( $query->is_home ) {
$query->set( ‘cat’, ‘-7, -43’ );
}
return $query;
}

add_filter( ‘pre_get_posts’, ‘hide_category_blog’ );

You can obtain category id by editing category. You will find the category id in the URL.

How to Hide Category from WordPress Blog Page

 

Facebook
Twitter
LinkedIn
WhatsApp
Telegram

I design and develop beautiful, creative, ultra-fast loading, and cost-effective websites. I specialize in WordPress website design, blog design and development, E-commerce Website development, Responsive web design, and WordPress support and maintenance services.

Looking for Better Opportunity?

Please feel free to fill out the form below and we will contact you shortly.