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 been using "if (is_single() && in_category('keyword') )" to display custom links on the sidebar. I was wondering if we have in_tag or any similar function for tags?

share|improve this question
up vote 2 down vote accepted

Here is the source of in_category function:

function in_category( $category, $post = null ) {
    if ( empty( $category ) )
        return false;

    return has_term( $category, 'category', $post );

You see, it's actually has_term. This is the same as has_category function.

For tags, there's no in_tag function, but you can use has_tag. It has the same functionality:

has_tag( $tag, $post );

Or you can use:

has_term( $tag, 'post_tag', $post );

where $post can be omitted (default is current post).

They're all the same!

share|improve this answer
I tried has_term before but it didn't work. However, has_tag works perfectly. I can't thank you enough. But I have a problem here. Is it possible to show custom links based on a generic tag? For example: I have tags like "iPhone News", "iPhone Apps" and I want to show custom links for "iPhone." I am using this code: <?php if (is_single() && has_tag('iphone') ) : ?> <ul><li><a href="http://...">Apple</a></li></ul><?php endif; ?> Replacing 'iphone' with 'iphone-news' shows custom links only on pages tagged with iPhone news. Once again, thanks for the help! – Sid Sep 5 '12 at 5:57
What is your custom link? BTW, if it doesn't related to this question, you should ask it separately. – Rilwis Sep 5 '12 at 8:05
These are links on the sidebar linking to "similar" pages, tags, categories, and so on. The function has_tag does it for me, but I was wondering if we can tweak it further. – Sid Sep 5 '12 at 9:39

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.