I have created custom post type Books in my functions.php. Now I want to redirect every user (assigned with editor role). When they click to Dashboard it goes to this page:


What I want:

enter image description here

add_action('load-index.php', 'redirect_dashboard');

function redirect_dashboard() {
  if ( ! is_admin() || current_user_can('activate_plugins') ) return;
  $screen = get_current_screen();
  if ( is_object($screen) && $screen->base == 'dashboard' ) {
    $url = admin_url('edit.php');
    wp_safe_redirect( add_query_arg( array('post_type' => 'product'), $url) );
  • It is also affecting to main administrator page. I want only editor role otherwise you code is perfect for me. Can you help me how to fix that also. – Avenger Aug 31 '13 at 2:03
  • @Manan I've edited the code. Just a little addition on first if. In the question you said "i want to redirect every user" not "i want to redirect every editor" or I would use this code on first publish. – gmazzap Aug 31 '13 at 2:14

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.