1

How can I redirect certain WordPress admin pages to another admin page.

For example I never want a user to see wp-admin/about.php it should always redirect to wp-admin/index.php.

There are also a couple plugins that redirect to a plugin welcome page with promotions the I want to be able to check if this URL then redirect to this URL.

2

You can use get_current_screen() to check on which page you are then make a redirect to specific admin page.

get_current_screen() return the screen object like

WP_Screen Object
(
    [action] => 
    [base] => dashboard
    [columns:WP_Screen:private] => 0
    [id] => dashboard
    [in_admin:protected] => site
    [is_network] => 
    [is_user] => 
    [parent_base] => 
    [parent_file] => 
    [post_type] => 
    [taxonomy] => 
    [_help_tabs:WP_Screen:private] => Array
        (
        )

    [_help_sidebar:WP_Screen:private] => 
    [_screen_reader_content:WP_Screen:private] => Array
        (
        )

    [_options:WP_Screen:private] => Array
        (
        )

    [_show_screen_options:WP_Screen:private] => 
    [_screen_settings:WP_Screen:private] => 
)

You can use base key to identify the page base!

Example:-

add_action('current_screen', 'wpse_225416_redirect_admin_page');
/**
 * Redirect specific admin page
 */
function wpse_225416_redirect_admin_page() {
    $my_current_screen = get_current_screen();
    if (isset($my_current_screen->base) && $my_current_screen->base == 'about') {
        wp_redirect(admin_url());
        exit();
    }
}

Use current_screen hook because before that get_current_screen() will return nothing.

  • So, if i need it to redirect back to the dashboard it should look like this? function wpse_225416_redirect_admin_page() { $my_current_screen = get_current_screen(); if (isset($my_current_screen->base) && $my_current_screen->base == 'about') { wp_redirect(admin_url('index')); exit(); } } – Shae May 2 '16 at 20:22
  • The current code in answer redirecting about.php to index.php! No need to add index in admin url admin_url('index') for dashboard. – Sumit May 3 '16 at 4:18
  • I've added the code above from the example, but I am still able to get to the about page. – Shae May 4 '16 at 13:46
  • I've tested it and it is working fine. Please debug, clear the cache, disable plugins and switch to default theme. It is hard to say why it does not work in your system, because it is very basic and working example. – Sumit May 4 '16 at 14:45
  • Question, if I need to redirect from this page: edit.php?post_type=newsletter&page=mymail_welcome to the dashboard, how should it be written? – Shae May 10 '16 at 16:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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