Categories

Featured templates

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

Kate Daniels October 21, 2015
Rating: 4.2/5. From 9 votes.
Please wait...

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

Premium Wordpress Templates
This entry was posted in WordPress Tutorials and tagged blog, category, exclude, page, WordPress. Bookmark the permalink.

Submit a ticket

If you are still unable to find a sufficient tutorial regarding your issue please use the following link to submit a request to our technical support team. We'll provide you with our help and assistance within next 24 hours: Submit a ticket