is_tag()
returns whether the query is for an existing tag archive page. This isn’t what you want to use.
Instead, use get_query_var()
.
get_query_var( 'tag' )
will look at the tag
query variable in the URL. For instance, if your URL is
https://example.com/?tag=this&other=that
then using:
get_query_var( 'tag' )
will returnthis
get_query_var( 'other' )
with returnthat
Instead of using a lot of ifs, we can use the PHP switch construct.
//* Use switch instead of a long series of ifs
$tag = get_query_var( 'tag' );
switch( $tag ) {
case 'northern-california':
$tag = 'Northern California';
break;
case 'seminar':
$tag = 'Seminar';
break;
//* Etc.
default:
$tag = 'All';
break;
}
//* Do something useful with $tag
But to use get_query_var()
for a custom query variable, we need to add the query var to the array of variable names that WordPress will retrieve using the function. This can go in your theme functions.php or in a simple plugin, as long as it’s loaded before you try to get_query_var()
.
The string name used in the get_query_var()
function must be exactly the same as the name used in the filter. If you want to use eventTag
as your query var, then you need to add that to the query_vars array and use that as the query var in the URL:
https://example.com/?eventTag=california
This would go in your functions.php file
//* Allow custom query var 'tag'
add_filter( 'query_vars', function( $vars ) {
//* Use whatever custom query var you want, but it needs to be exactly the same
$vars[] = 'tag';
$vars[] = 'eventTag';
return $vars;
}, 10, 1 );
If you don’t like using closures:
add_filter( 'query_vars', 'wpse_261930_query_vars', 10, 1 );
function wpse_261930_query_vars( $vars ) {
$vars[] = 'tag';
return $vars;
}
It’s unclear how you would structure your URL for two different tags.