Aleš Sýkora / July 1, 2021 / 0 comments

WordPress term list without links

Post summary: If you use the_terms for list of posts taxonomy terms, then you get the list with automatically added links. Sometimes you do not need the links. Then you can use the strip_tags. Get term list with links Get term list without links Get the terms custom output

If you use the_terms for list of posts taxonomy terms, then you get the list with automatically added links. Sometimes you do not need the links. Then you can use the strip_tags.

Get term list with links

<?php the_terms( 0, 'tax-slug'); ?>

Get term list without links

<?php echo strip_tags(get_the_term_list( $post->ID, 'tax-slug', ' ',', ')); ?>

Get the terms custom output

<?php
global $post;
$terms = get_the_terms( $post->ID, 'tax-slug');
if ($terms > 0) {
    foreach($terms as $term) {
        echo '<a class="c-text-s c-link-accent" href="' . get_term_link($term) .'">' . $term->name . '</a>';
    }
}
?>

Fuel my passion for writing with a beer🍺

Your support not only makes me drunk but also greatly motivates me to continue creating content that helps. Cheers to more discoveries and shared success. 🍻

0 comments

Share Your Thoughts