Where to add wp_redirect on frontend pages?

I found that currently this is the only reliable solution: if (is_admin()){ header(‘Location: ‘. get_permalink()); exit(); } else add_action(‘template_redirect’, function (){ wp_redirect(get_permalink()); exit(); }); In the case of backend pages the template_redirect does not seem to be supported. If I use wp_redirect the redirection does not happen (maybe it is a bug) or the function … Read more

wp_redirect problem using code snippets

You can’t use wp_redirect or make HTTP redirects from inside a shortcode, redirects must happen before HTTP headers are sent out, before any HTML is sent to the browser, so shortcodes will always be too late. So I looked around and I believe the problem is that some content is sent to the browser before … Read more

wp_redirect() doesn’t work

The problem is not what you are doing, but when you are doing it. When your browser requests a webpage, that webpage arrives with a set of HTTP headers, followed by a HTTP body that contains the HTML. Redirection is done via a HTTP header. The moment you echo, or printf or send any form … Read more