I have this specific tag I need to assign to my posts but I need to hide it from regular visitors so that only logged in people can see it. How do I go about it? What WordPress function/hook should I be looking into?

I know that I could use is_user_logged_in() and I am also looking into is_tag(), but how do I put this together? Currently I'm having it displayed in my single template with the_tags(), but it doesn't seem to offer a parameter to exclude a particular tag.

Pseudo code would be: if user is logged in then show all tags except a specific tag.

  • So, solution if fine but how do I make the solution to work for two or more tags ? Anyone or should I be asking this in a new question. ?
    – gurung
    Mar 22, 2014 at 10:30
  • got it. if($tag->slug=='tag_one' OR $tag->slug=='tag_two'){
    – gurung
    Mar 22, 2014 at 11:54

1 Answer 1


Add the add_filter to your theme's functions.php file

function myTags() {
$posttags = get_the_tags();
if ($posttags) {
  foreach($posttags as $tag) {
      if($tag->slug=='your specific tag slug'){
        if(is_user_logged_in() ) {
    echo '<a href='.get_tag_link($tag->term_id).' >'.$tag->name . '</a> '; 
    } else {
         echo '<a href='.get_tag_link($tag->term_id).'>'.$tag->name . '</a> '; 
add_filter('the_tags', 'myTags');
  • Works perfectly. What changes will be made if there are two or more tags to be exluded ?
    – gurung
    Mar 22, 2014 at 9:48
  • @gurung add more tags in if condition with OR operator
    – dipali
    Mar 22, 2014 at 9:52
  • @DipaliDhole if($tag->slug=='tag_one' OR 'tag_two') { does not work. also how come the code works with the same if statement, amazing.
    – gurung
    Mar 22, 2014 at 10:14
  • 1
    It is the same but the first <a> is echoed only for logged users, so it won't be visible for not logged users (but not logged users can still access to the tag archive URL if they know it).
    – cybmeta
    Mar 22, 2014 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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