• I’ve created an archive category. Full of posts back from when I started that rank well (in which case I don’t want to delete) but are no longer relevant.

    Is there a way to hide these posts from my blogroll so they’re only shown if someone searches for that specific search term?

    Thanks in advance

Viewing 2 replies - 1 through 2 (of 2 total)
  • You can use the pre_get_posts hook to hide posts from a category in your homepage. Try adding this to your theme’s functions.php

    function my_exclude_category( $query ) {
        if ( $query->is_home() && $query->is_main_query() ) {
            $query->set( 'cat', '-1' ); // change 1 to the ID of the archive category.
        }
    }
    add_action( 'pre_get_posts', 'my_exclude_category' );

    Note that you would need to do this in a child theme if you would not want this to get lost on a theme update.

    Thread Starter tmm104

    (@tmm104)

    Thanks guys! Much appreciated. 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Is there a way to 'hide' a catagory’ is closed to new replies.