-2

I've searched for this for a while (also SO), but I just don't get it. I want to place an echo <?php echo get_tag_link($tag_id); ?> within an echo:

<?php
    $posttags = get_the_tags();
    $count=0;
    if ($posttags) {
        foreach($posttags as $tag) {
        $count++;
            if (1 == $count) {
                echo '<span class="tags"><a href="<?php echo get_tag_link($tag_id); ?>">';
                echo $tag->name . ' ';
                echo '</a></span>';
            }
        }
    }
?>

But clearly this is wrong..

ezkay
  • 119
  • 1
  • 2
  • 9

2 Answers2

1

You have to change the row to:

echo '<span class="tags"><a href="' . get_tag_link($tag_id) . '">';
Krycke
  • 3,106
  • 1
  • 17
  • 21
1

You're already working within a PHP block so you don't need the <?php ?>

Similarly you're already echoing a string so the echo is also not needed.

What you're looking for is concatenation

Like this:

echo '<span class="tags"><a href="' . get_tag_link($tag_id) . '">';
danjam
  • 1,064
  • 9
  • 13
  • That was what i was trying to do, thanks, man! I knew that the secound PHP was wrong and that i hat to work with the dots somehow.. I'm too noobish, sorry ^^ – ezkay Dec 03 '15 at 14:47