Archived topic
Hide Category
5 replies · Started by Kumari on July 4, 2020
Hi There
I was wondering if it is at all possible to hide a specific category from showing up on my site?
I have some archived content (blog posts) that I need to keep due to backlinks and keywords etc but I do not want these to show up when people are browsing my site.
Please let me know if it is possible to do this without using a plugin?
Thanks in advance.
Hi there,
Where/how would they currently find the category? When searching for posts?
They could possibly come across it using 'post navigation' and when searching for posts.
I don't mind it showing up with search but would prefer that it not show up via post navigation.
In that case, you should be able to do this:
add_action( 'pre_get_posts', function( $query ) {
if ( $query->is_main_query() ) {
$query->set( 'cat', -10 );
}
} );
You just need change 10 to the ID of the category you're wanting to exclude.
This works perfectly! Thank you SO much!
You're welcome :)