Home / admin / Redirect admin pages to any location
  • How to Redirect admin pages to any location


    Redirecting the admin pages was something I needed to do for a recent project. The following snippet will let you redirect any of the admin pages to any location you wish based on the user ‘capability’. Another option would be to replace wp_redirect with wp_die(“some custom message”); to display a message instead of redirecting.

    ( click code to copy )

    wordpress snippet : PHP

    function wpsnipp_admin_pages_redirect() {
          global $pagenow;
          $admin_pages = array(
          if(in_array($pagenow, $admin_pages)){
          	wp_redirect( admin_url('/') ); exit;
    add_action('admin_init', 'wpsnipp_admin_pages_redirect');

    ( WordPress codex functions, hooks, in this snippet. )

    wp_redirect, edit_post, init, current_user_can, user_can, add_action, admin_url, wp,
  • Bryan

    You can’t use current_user_can() when in the global scope, within a plugin because it will cause Fatal error: Call to undefined function wp_get_current_user().