You’re not passing the actual querystring to remove_query_arg()
. After some quick testing, I think your $location
value is probably an empty string, and the location you’re attempting to redirect to is ?isPwa
.
The 2nd parameter to remove_query_arg()
should be the $referer
value.
function addIsPwaQueryArg() {
$referer = wp_get_referer();
if (strpos($referer, 'isPwa') !== false) {
$location = remove_query_arg('isPwa', $referer );
wp_redirect(add_query_arg('isPwa', '', $location));
exit;
}
}
add_action('template_redirect', 'addIsPwaQueryArg');
However: I’m not sure that’s the root cause of your redirect loop. It looks like you’re checking to see if isPwa
is in the querystring, removing it if it is, and then adding it back in (with a blanked value) as you redirect. Is this your intent?