Display tags in list without link

This seems like it should be something that’s really simple to do, however it’s apparently not.

I don’t want tags to be links, but I want them to display in an unordered list, with each tag inside an <li>

Read More

get_the_tags allows you to echo them without the associated link, but I have no idea how to wrap them in li’s.

 <?php
$posttags = get_the_tags();
if ($posttags) {
  foreach($posttags as $tag) {
    echo $tag->name . ' '; 
  }
}
?>

Related posts

Leave a Reply

3 comments

  1. This would do it…

     <?php
    $posttags = get_the_tags();
    if ($posttags) {
      echo '<ul>';
      foreach($posttags as $tag) {
        echo '<li>' .$tag->name. '</li>'; 
      }
      echo '</ul>';
    }
    ?>
    
  2. add_action( 'loop_start', 'list_tags' );
    
    function list_tags() {
    
    $tags = get_tags( array('orderby' => 'count', 'order' => 'DESC') );
    
    foreach ( (array) $tags as $tag ) {
    
    echo '<li>' . $tag->name . '</li>';
        }
    }
    

    Use any WordPress or theme specific hook from your functions file.

  3. This is my preferred solution, to wrap the request with strip_tags to retain formatting options. Here is the code:

    <?php echo strip_tags ( get_the_tag_list( '<span>', ',&nbsp;', '</span>' ) ); ?>
    

    You can also do this for categories.

    <?php echo strip_tags ( get_the_category_list( '<span>', ',&nbsp;', '</span>' ) ); ?>