Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

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.

like image 757
Robin Cox Avatar asked Sep 15 '26 17:09

Robin Cox


1 Answers

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;
like image 148
James Scholes Avatar answered Sep 20 '26 16:09

James Scholes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!