WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a term that I'd like logged in admin users to see while they're browsing the site while keeping it hidden from the public.

I'd prefer to have it done at the lowest level possible, even so far as to prevent the term from showing up publicly with any of the functions (e.g wp_list_categories).

What's the best way to pull this off?

share|improve this question
up vote 1 down vote accepted

Currently we can not pass user_ID or user_role to wp_list_category() function, So it is not possible unless you use filter to do this, that is bit complicated so here I has a solution that does exact what you want without using filter.

if ( current_user_can( 'manage_options' ) ) {
    /* A user with admin privileges */
    wp_list_categories(); ?
} else {
    /* A user without admin privileges */
    wp_list_categories('exclude=4');  // 4 is id of category you'd like to hide

Update -

I think using the get_category() function will be good idea, First grab all the categories as array and then show them as required.

        $categories = get_categories();
        if(!current_user_can( 'manage_options' )) {
            $exclude = 4; // category ID to hide from non admin
        } else {
            $exclude = '';

        foreach ( $categories as $cat ) {
            if($cat->term_id != $exclude) {
                echo '<li>'.$cat->name.'</li>';
share|improve this answer
This works for wp_list_category and I may accept it... How about get_the_term_list, though? – Jonathan Wold Aug 6 '12 at 22:04
I updated my answer with simple example. – amit Aug 6 '12 at 23:23
I like it - Not what I was thinking, but it is a simple answer that works! I'm accepting it. – Jonathan Wold Aug 20 '12 at 20:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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