0

I'm using this Twig code to display tags on my posts. However, I can't figure out how to get the Tags: title to hide itself when there are no tags. If there's no tags, it just shows Tags: , which of course looks ugly.

The code I'm trying below doesn't work and gives me a bunch of errors. Any suggestions what I'm doing wrong?

   {% if post.tags_count > 0 %} <span>Tags:
    {% for tag in post.tags %}
        <a href="{{ tag.link }}" class="{{ 'tag-' ~ tag.slug }}">{{ tag.name }}</a>
        {% if not loop.last %}, {% endif %}
    {% endfor %}
    </span>
   {% endif %}
  • 1
    What are the errors? This seems more about Twig syntax than WP mechanics to me. – Rarst Jun 22 '14 at 20:33
  • Try if post.tags instead of if post.tags_count > 0 – TheDeadMedic Jun 23 '14 at 8:50
  • For the sake of readability, please properly format your code before adding it to your question. Thanks – Pieter Goosen Jun 23 '14 at 16:54

Your Answer

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

Browse other questions tagged or ask your own question.