Ok, so this is what i understand.
You want the ppc value to show up on your page in the h1, but only if that value is in the list of valid options, then if the ppc is not value is would be an empty h1 tag.
If it matters, the display of the ppc value is dependent on what the url contains. So if i pass domainname.com?ppc=super hero, the ppc display value would be “super hero”, but if domainname.com?ppc=Super Hero, then the ppc display value would be “Super Hero”. If you want “Super Hero” to be the display value for “super hero” then you can change the function to set a default display value for valid choices.
If this is what you want, I think this can be accomplished without using the add_action(‘parse_query’… and in where you want to display the value.
Delete the original function and the add_action lines, but keep the add_custom_query_vars_filter and its filter line.
put this function in your functions.php file
function get_ppc_value_if_valid( $default = '', $beforeText = '', $afterText = '' ) {
// check if we have the ppc query string var
if (($ppcValue = get_query_var('ppc', 'nope')) != 'nope') {
// setup the valid choices with the display values
$validPPCChoices = [
'super hero' => 'Super Hero',
'easy way home' => "Easy Way Home"
];
if (in_array(strtolower($ppcValue), $validPPCChoices)) {
// the ppc value is valid
return $beforeText. $validPPCChoices[strtolower($ppcValue)].$afterText;
} else {
// the ppc value is NOT valid
}
}
return $default;
}
Then in your template used this where you want the ppc value to be displayed,
echo get_ppc_value_if_valid('', '<h1>', '!</h1>');
So with the modified code, for the url, domainname.com?ppc=super hero, it would return <h1>Super Hero!</h1>, and for domainname.com?ppc=super hero2, it would echo nothing. It would not create an empty <h1> tag.