• Hey guys,

    i have a simple problem.
    I want use this code to print out the tags of a post:

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

    The result is for example this “tag1, tag2, tag3,”

    What can I do to make the last comma away.

    Thank You.

Viewing 2 replies - 1 through 2 (of 2 total)
  • $posttags = get_the_tags();
    
    if ( ! empty($posttags) ) {
        $ltag = end($posttags);
    
        foreach($posttags as $tag) {
    
            if ($tag->name == $ltag->name ) {
              echo $tag->name;
            } else {
              echo $tag->name . ', ';
            }
        }
    }
    Thread Starter Sascha

    (@ironman95)

    Thank you very much ricoh.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Post Tags in WordPress’ is closed to new replies.