将single_tag_title存储在变量中

Rob*_*Cox 1 tags variables wordpress archive echo

在Wordpress中,以下内容将在存档列表中回显当前选择的标签:

single_tag_title();
Run Code Online (Sandbox Code Playgroud)

有谁知道如何将其存储在变量中,以便我可以使用像这样的普通php变量回显相同的字符串:

echo $tagSlug; //This shows the same string as the single_tag_title() function
Run Code Online (Sandbox Code Playgroud)

我已经试过了:

$tagSlug = single_tag_title();
echo $tagSlug;
Run Code Online (Sandbox Code Playgroud)

但这是行不通的。

Jam*_*les 7

single_tag_title接受两个参数。$ prefix和$ display。$ prefix设置应该在标签之前回显/返回的字符串,而$ display确定是否将标签作为变量回显或返回。请参阅此处的文档

$tagSlug = single_tag_title("", false);
echo $tagSlug;
Run Code Online (Sandbox Code Playgroud)