1

So you need this to happen before Wordpress has output anything at all, otherwise you won't be able to send a redirect. A way to achieve this is with the template_redirect hook, documented here: https://codex.wordpress.org/Plugin_API/Action_Reference/template_redirect The example from that docs page is more or less exactly what you want. I've edited it a ...


1

As you can see from the source code, wp_redirect always ends in a PHP header request, except if the location is empty, because then it doesn't know where to redirect. So you can indeed use the wp_redirect filter. If you return an empty string under certain circumstances, the redirect will not happen.


Only top voted, non community-wiki answers of a minimum length are eligible