WordPress.org

Ready to get started?Download WordPress

Forums

Toolbox
[resolved] Exclude Categories from index (3 posts)

  1. Sherry
    Member
    Posted 10 months ago #

    I am stumped on how to exclude categories from the index.php page using the excerpt tag. I used to be able to do it, but can't find it in your theme.

  2. Kathryn
    Automattic Happiness Engineer
    Posted 10 months ago #

    Hi Sherry, there are a few different ways to exclude categories from the blog homepage, but a simple one that works in any theme, with both excerpts or full posts, is described here:

    http://www.locoed.com/web-design/how-to-exclude-category-posts-wordpress-tutorial-code/

    It's the section called "Code to Exclude Category Posts in WordPress" and it's a function that looks like this:

    function exclude_category($query) {
    if ( $query->is_home() ) {
    $query->set('cat', '-xx');
    }
    return $query;
    }
    add_filter('pre_get_posts', 'exclude_category');

    You'd replace xx with the category ID you want to exclude.

    Let me know if this does the trick.

  3. Sherry
    Member
    Posted 10 months ago #

    Thank you!!!

Reply

You must log in to post.

About this Theme

About this Topic