Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am currently trying to setup a redirect so that my admin users are redirected to a page other than the dashboard within the wordpress administrator interface.

If I leave out my conditional, the redirect works, but then it also redirects non-administrator users as well and I don't want this.

Here is the code I have within functions.php

add_filter('login_redirect', 'dashboard_redirect');
function dashboard_redirect($url) {
  global $current_user;
  get_currentuserinfo();
  $level = (int) $current_user->wp_user_level;

  if ( $level > 10  ) {
    $url = 'wp-admin/edit.php';
  }

  return $url;
}     
share|improve this question
    
How about accepting answers that certainly saved you time as correct? –  Johannes Pille Nov 25 '11 at 23:47

3 Answers 3

You should not use Userlevels. Userlevels have been replaced in WP 2.0 and have been officially deprecated since 3.0

function dashboard_redirect($url) {
    global $current_user;
    // is there a user ?
    if(is_array($user->roles)) {
        // check, whether user has the admin role:
        if(in_array('administrator', $current_user->roles)) {
             $url = 'wp-admin/edit.php';
        }
        return $url;
    }
}
add_filter('login_redirect', 'dashboard_redirect');    

Will do what you want.

share|improve this answer

Yan also add this simple action to the 'login_form' (see this site for more detail).
For example, to redirect to dashboard, you can use:

add_action('login_form', 'redirect_after_login');
function redirect_after_login() {
    global $redirect_to;
    if (!isset($_GET['redirect_to'])) {
        $redirect_to = get_option('siteurl') . '/wp-admin/index.php';
    }
}
share|improve this answer
    
this worked great for me. –  TJ Sherrill Apr 23 '13 at 15:55

Try wrapping the function with this current_user condition:

if (current_user_can('administrator')) {
// Your Redirect Code Here
}
share|improve this answer

Your Answer

 
discard

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.