WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am doing the following in my plugin:

  1. Register a custom admin page and in the callback function (the last parameter of add_submenu_page)

  2. Redirect to another page

However, when I open the custom admin page I get the following error:

Warning: Cannot modify header information - headers already sent by (output started at ..\wp-admin\includes\template.php:1637) in ..\wp-includes\pluggable.php on line 878

Here's the callback function:

function myplugin_callback(){
share|improve this question
up vote 3 down vote accepted

You can't redirect to another page, because WordPress has already rendered admin header and sidebar templates. If you really wish to redirect users to another page, you need to do it earlier, before header and sidebar are rendered. You can use action of following structure to redirect to another page:


The full snippet:

define( 'WPSE8170_REDIRECT_PAGE_SLUG', 'wpse8170-redirect-page' );

add_action('admin_menu', 'register_my_custom_submenu_page');
function register_my_custom_submenu_page() {
    add_submenu_page( 'tools.php', 'My Custom Redirect Page', 'Redirect Page', 'manage_options', WPSE8170_REDIRECT_PAGE_SLUG, 'wpse8170_redirect_page_callback' );

function wpse8170_redirect_page_callback() {
    // ...

add_action( 'load-tools_page_' . WPSE8170_REDIRECT_PAGE_SLUG, 'wpse8170_mypage_redirect' );
function wpse8170_mypage_redirect() {
    if ( WPSE8170_REDIRECT_PAGE_SLUG == filter_input( INPUT_GET, 'page' ) ) {
        wp_redirect( 'http://google.com' );
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.