exclude - is there a quick way to hide category from everywhere?

admin2025-04-20  0

I want to get rid of some posts, old ones, that I don't really want to keep. I was thinking to create a category named 'old' and use it as a garbage can to trash everything I don't like from old posts.

Reason I don't simply delete them is the google traffic. Some of those pages receive 1-2 visits a day, so why not leave them? just as adsense traffic :)

Anyhow.

Now I need a way to hide category 'old' from everywhere. I need a quick and dirty way to do this, preferably through functions.php - don't want to change every menu listing and add -old.

I also want to exclude posts inside this category from being displayed in 'related posts' section. But for this I guess I will have to take a look in the plugin itself...

any help?

Thanks!

I want to get rid of some posts, old ones, that I don't really want to keep. I was thinking to create a category named 'old' and use it as a garbage can to trash everything I don't like from old posts.

Reason I don't simply delete them is the google traffic. Some of those pages receive 1-2 visits a day, so why not leave them? just as adsense traffic :)

Anyhow.

Now I need a way to hide category 'old' from everywhere. I need a quick and dirty way to do this, preferably through functions.php - don't want to change every menu listing and add -old.

I also want to exclude posts inside this category from being displayed in 'related posts' section. But for this I guess I will have to take a look in the plugin itself...

any help?

Thanks!

Share Improve this question asked Oct 19, 2011 at 22:03 user8842user8842 1
  • I think there are other ways to hide a category without coding such as password protect it or use a category excluder plugin. I've searched around and found this article that you can reference: passwordprotectwp/hide-category-wordpress – suzie Commented Sep 26, 2019 at 5:05
Add a comment  | 

4 Answers 4

Reset to default 3

pre_get_posts is the right hook for this

since i just did category exclusion in another answer i will post it here too. Exclude the category from the WordPress loop

based on the codex sample:

http://codex.wordpress/Custom_Queries#Category_Exclusion

add_action('pre_get_posts', 'wpa_31553' );

function wpa_31553( $wp_query ) {

    //$wp_query is passed by reference.  we don't need to return anything. whatever changes made inside this function will automatically effect the global variable

    $excluded = array(272);  //made it an array in case you need to exclude more than one

    // only exclude on the front end
    if( !is_admin() ) {
        $wp_query->set('category__not_in', $excluded);
    }
}

There's a plugin for that :-)

http://wordpress/extend/plugins/hide-categories/

can you try this, add in your function.php

add_action('pre_get_posts', 'block_category' );
function block_category() {
global $wp_query;   
$wp_query->query_vars['cat'] = '-1';
}

replace -1 with your cat id

can you try again with a conditional tag

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

xx is your category

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745128776a286587.html

最新回复(0)