0

How do I make sure that articles from certain category do not display on main page?

I want them to display on a subpage only.

So let's say I have 7 articles under "main".

I want all of these to display on main page, homepage.

Then let's say I have 20 articles on "category1".

I want them all to display in website.com/category1 but not on main page.

1
  • I removed the request for plugins as that would get your question closed as offtopic. This is a developer stack so you should expect a technical answer. If it was a recommendation you wanted you should ask on the software recommendations stack instead
    – Tom J Nowell
    Oct 5, 2022 at 11:17

1 Answer 1

1

Example of a function to remove post category from the home page.

function exclude_category_home( $query ) {
    if ( $query->is_home ) {
        $query->set( 'cat', '-5, -34' );
        }
    return $query;
}

add_filter( 'pre_get_posts', 'exclude_category_home' );

Replace the category ID with the one you want to exclude. Add to functions.php of your child theme.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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