Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect to different admin page in Wordpress?

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?

like image 892
dr_bonzo Avatar asked Jan 30 '09 13:01

dr_bonzo


2 Answers

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">
like image 137
codecowboy Avatar answered Sep 29 '22 23:09

codecowboy


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"

like image 43
zero_padded Avatar answered Sep 29 '22 21:09

zero_padded