I am writing a Wordpress plugin.
I want to perform a redirect (after creating DB records from POST data, etc...) to other ADMIN page.
Neither header("Location: ...) nor wp_redirect() work - i get
Warning: Cannot modify header information - headers already sent by
which comes from obvious reason.
How do I properly perform a redirect in a Wordpress?
On your form action, add 'noheader=true' to the action URL. This will prevent the headers for the admin area from being outputted before your redirect. For example:
<form name="post" action="<?php echo admin_url('admin.php?page=your-admin-page&noheader=true'); ?>" method="post" id="post">
If you still want to redirect from your plugin admin page to another admin page while using WP add_page* functions then, after processing your request, you can just echo something like this:
<script type="text/javascript">
window.location = '/whatever_page.php';
</script>
This just renders a javascript based redirect to "/whatever_page.php" thus ensuring no trouble with headers already sent by WP as Chris Ballance already said.
Change "/whatever_page.php" to something like "/wp-admin/admin.php?page=whatever_page"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With