What’s the proper way of doing a redirect from within a plugin?
By the time the code in my plugin is executed, WordPress has already printed out the header to the browser, so I don’t see how it’s possible to do a 302/301 redirect from inside a plugin.
I don’t want to do a Javascript redirect for obvious reasons!
Thanks
If the wp_redirect is called too late, you might not be able to use it (not sure where in your execution you’re calling it). Assuming this is a redirect within an admin plugin page, an alternative is to capture the output in a buffer, which means you can still send headers. An example I’ve used is:
Obviously change the names etc, but that should let you then use header() anywhere in your plugin page. It does have some downsides however, errors won’t be displayed by default etc, so use at your own risk.