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:
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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With