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>

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 . ' '; 
  }
}
?>

3 Answers
3

This would do it…

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

Leave a Comment