3

This code:

<?php the_terms($post->ID, 'type') ?>

Gives:

<a href="/archives/type/image" rel="tag">Tag</a>  

What do to if I want to display only "Tag" word, not link eg.

Tag

Thanks!

2 Answers 2

8

While you can specify separators and such in the_terms() arguments, it assumes that you actually want links.

You can discard unwanted HTML by using filter:

add_filter('the_terms', 'no_terms_links', 10, 2);

function no_terms_links($term_list, $taxonomy) {

    if ('type' == $taxonomy)
        return wp_filter_nohtml_kses($term_list);

    return $term_list;
}

Or just use deeper get_the_terms() function and iterate through its return to build your own markup.

4
  • I've added your code, but I'm still getting links :( Dec 9, 2010 at 16:00
  • 2
    Don't forget to change type to your actual taxonomy in snippet.
    – Rarst
    Dec 9, 2010 at 17:29
  • 4
    At a super-duper simple scale, what about just echo strip_tags( get_the_term_list($post->ID, 'type') ) ? Dec 9, 2010 at 18:00
  • Yeaah, that would do it... I deem today - the day of overthinking code. :)
    – Rarst
    Dec 9, 2010 at 18:14
-1

At a super-duper simple scale, what about just:

echo strip_tags( get_the_term_list($post->ID, 'type') )
1
  • 1
    What about it? Does it work? What does it do? Is this an answer and how does it help?
    – kaiser
    Oct 17, 2014 at 10:46

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.