• Hi, i’m trying to display the tag count (number of tags) for a post but i can’t find the right php code. Any ideas? Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Have you tried using get_the_tags()?

    Thread Starter yeshileyed

    (@yeshileyed)

    Thank you for your reply but i’ve already tried get_the_tags()

    What i want to show is total tag count for a post. If anybody knows the code please paste it as a reply, thank you…

    What i want to show is total tag count for a post.

    – I guess I’m not understanding what you’re trying to do.

    For example, say a post is tagged “WordPress”, “CMS”, and “PHP”. Are you wanting to display something like “This post has 3 tags”?

    If that is the case the get_the_tags() will work since it returns an array of objects, one object for each tag assigned to the post. Have you tried something like:

    $post_tags = get_the_tags();
    $tag_count = count($post_tags);
    
    if ( $tag_count ) {
      echo "This post has $tag_count tags";
    }
    else {
      echo "This post does not have any tags";
    }

    Thread Starter yeshileyed

    (@yeshileyed)

    Hi, thank you for your reply and help, i’ve pasted the code above but i’m always having “This post does not have any tags” message even for tagged posts. I think code need to be modified.

    Without seeing the code in context it’s hard to say why it’s not working. Can you paste the entire file into a pastebin and then post that link here?

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Tag count?’ is closed to new replies.