Storing single_tag_title in variable

In WordPress, the following will echo the currently chosen tag in an archive listing:

single_tag_title();

Does anybody know how to store it in a variable, so that i can echo out the same string using an ordinary php variable like this:

Read More
echo $tagSlug; //This shows the same string as the single_tag_title() function

I have tried this:

$tagSlug = single_tag_title();
echo $tagSlug;

But it doesn’t work.

Related posts

Leave a Reply

1 comment

  1. single_tag_title accepts two arguments. $prefix and $display. $prefix sets the string which should be echoed/returned before the tag, and $display determines whether the tag is echoed or returned as a variable. See the documentation here.

    $tagSlug = single_tag_title("", false);
    echo $tagSlug;