This is for 11Mystics (and anyone else curious). The following is how I’m currently grabbing the tag query string for display purposes. Inside my functions.php file is the following:
function my_get_the_tag_query() {
$nice_tag_query = $_SERVER['REQUEST_URI'];
$nice_tag_query = str_replace('/tag/','', $nice_tag_query);
$nice_tag_query = str_replace(',', ', ', $nice_tag_query);
$nice_tag_query = str_replace('/','', $nice_tag_query);
return $nice_tag_query;
}
Quick explanation: The above assumes a permalink structure where the base for all tag pages is “/tag/” (e.g. “www.example.com/tag/”). The function grabs part of the URL/URI string and then uses the str_replace()
function to clean up the output by removing the “tag” and slashes. Right now, I’m leaving the plus signs as is and just adding a space after any comma.
For the web page title, just echo
the output of this function. If you’re using a common header file, then add an extra conditional statement for the title section, using WordPress’ is_tag()
function.