I'm currently developing a wordpress blog site but I think this question maybe a bit of JS magic at the same time so put it here rather than Wordpress Development.

I'm looking to create a post and have a certain div display on the post when a tag criteria is met e.g. if I tag a post with 'crazy css trick' I'm looking to display a badge on the post with 'Crazy CSS tricks' written on it. But also still allowing me to tag the post with multiple tags not just 1.

(This is similar to a 'featured' post and displaying a 'Featured' badge on the post)

This is Wordpress Would love to have this in the main loop. TL;DR

Wordpress Site Allowing Multiple Tags Displaying a certain tag on the post in the form of a badge Needs to be in main loop. A site which does similar to this is VEVO which you can see here http://www.vevo.com/ on their slideshow they have 'Exclusive' 'Original Show' Etc.

Any help would be great, tried a few ways but they seem to either do 'if' statements for every post and not exactly great performance wise.


  • The VEVO website seems to use more of a post category, then a post tag. I am not sure I follow your entire question. You want to be able to display the tag as a badge? But only one tag, not all?
    – gdaniel
    Dec 31 '14 at 16:04

You could use a simple conditional and check if the post has a term using has_term():

has_term( $term, $taxonomy, $post );

Pass in your Term Slug, the taxonomy ( which sounds like you're using post_tag and the post object, no javascript needed.

<?php if( has_term( 'term_slug', 'post_tag', $post ) : ?>

        Show your div here!

<?php endif; ?>
  • Apologies for this silly comment but how would I go about showing the div for posts tagged as 'CSS Trick'? Can you leave fields blank? or does it need custom taxonomy?
    – Jonathan
    Jan 3 '15 at 15:24
  • You don't need a custom taxonomy. If you're using the built in posts you already have 2 taxonomies: category ( hierarchical categories ) and post_tag which is the one you enter on the fly ( you can't assign a parent to these ). So if we assume your title is CSS Trick then the slug would be css-trick and you would just add that in the place of term_slug in my code. Let me know if you have any other questions.
    – Howdy_McGee
    Jan 3 '15 at 19:20
  • Hmm does there need to be a term_slug? As I just essentially want to place in a certain tag then make the div appear when it has that certain tag. (Apologies starting on Wordpress and can't seem to grasp this concept!)
    – Jonathan
    Jan 3 '15 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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