As you know, we can assign a "Category" to any post we write. We can also use a "Category" as link on the menu. Good!

By default, WordPress will display all your posts in all the categories on your front page.

However, how to prevent Wordpress displaying a "Category" type on the front page? Example, I have a post with a category name "Football". I don't want all posts with this category to be displayed on the front page, how to do that? I will access it only on the menu.



You can use pre_get_posts

Exclude categories on your main page

function exclude_category( $query ) {
    if ( $query->is_home() && $query->is_main_query() ) {
        $query->set( 'cat', '-1,-1347' );
add_action( 'pre_get_posts', 'exclude_category' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.