If this tutorial is not what you were looking for, you still have any questions, suggestions or concerns - feel free to let us know. Please help us to serve you better!

Your Name

Your Email

Your Message (required)

captcha

Featured templates

WordPress. How to exclude a category from displaying on Blog page

This tutorial will show you how to exclude posts assigned to specific category from displaying on Blog page in WordPress.

WordPress. How to exclude category from displaying on Blog page

  1. Log into your WordPress dashboard, and navigate to Appearance > Editor:

    WordPress_How_to_exclude_category_from_displaying_on_Blog_page

  2. Choose themeXXXXX, where XXXXX is your actual theme number in Select theme to edit drop down:

    WordPress_How_to_exclude_category_from_displaying_on_Blog_page_1

  3. Find custom-function.php file and open to edit it.

    WordPress_How_to_exclude_category_from_displaying_on_Blog_page_2

  4. You will need to get your category ID before editing this file. You should navigate to Posts > Categories:

    WordPress_How_to_exclude_category_from_displaying_on_Blog_page_3

  5. Hover over the category name (that you want to exclude from blog page) to see its ID:

    WordPress_How_to_exclude_category_from_displaying_on_Blog_page_4

  6. Add this code to the very end of the file before closing php tag ?> and replace 6 with your category ID:

    function exclude_category( $query ) {
    if ( $query->is_home() && $query->is_main_query() ) {
    $query->set( 'cat', '-6' );
    }
    }
    add_action( 'pre_get_posts', 'exclude_category' );
    
  7. Click Update file button to save changes.

  8. If you want to exclude 2 or more categories, you should separate them with comma in the code, example:

    $query->set( 'cat', '-6,-7' );
  9. Refresh your Blog page, now it doesn’t display posts from the category that was excluded in the file.

Feel free to check the detailed video tutorial below:

WordPress. How to exclude category from displaying on Blog page