Support » How-To and Troubleshooting » change login redirect

change login redirect

Viewing 15 replies - 1 through 15 (of 26 total)
  • OK so I’ve noticed that if I change $redirect_to in wp-login.php I can SORT OF control where users are sent upon login. However, it only seems like my admin login is using that value, whereas users I have added after setting up the site are being redirected to the profile page. Any ideas what is happening?

    More self discovery – obviously making the changes to $redirect_to only effects the LOGIN redirection, and does nothing to the logout. So I’ve had to change the header redirect value under the case:logout section as well. Unfortunately, I’m still having issues with regular users being appropriately redirected, only the admin account is being redirected appropriately.

    why isn’t it an option in the administrative control panel

    Because if every esoteric option was in the administrative control panel we’d need a 3-monitor system and a gig of server space to host the admin pages :).

    That said, which of the many $redirect_to assignments are you modifying?

    Because if every esoteric option was in the administrative control panel we’d need a 3-monitor system and a gig of server space to host the admin pages :).

    I’m not so sure I agree that this is an esoteric option. I definately agree that every option can’t be catered to, but at the very least an option between “redirect to last page” or “redirect to profile page” should exist. The majority of times someone logs into a site they are not going to be modifying their profile settings, but rather accessing content they have access to as a registered user.

    Anyway, that aside, I’m modifying the first $redirect_to assignment under the default: case – the rest I’ve left alone.

    I’m not so sure I agree that this is an esoteric option.

    Granted you might think it’s not, but for the seeming majority of WordPress users — single-author blogs — an option to control where the login redirect goes isn’t overly necessary.

    Try modifying this one on line 178.

    $redirect_to = get_settings('siteurl') . '/wp-admin/profile.php';

    That’s likely the one getting hit in those cases.

    dmarkd, if the line CF gave you works, could you post the relevant code-tweak? I’d like this better myself, but I am NO php code-jockey! Talk about breaking things….

    I think this is a great idea. Ideally it would direct you back to where you were.

    The line CF identified is helpful. At first, it appeared to have no effect and then I realized the code has a user = level 0 conditional. So I changed that redirect by putting a semi-colon after (‘siteurl’) and then a space and then slash-slash to comment out the rest of the line. That way I can undo it easy. That redirects level zeros to the home page.

    Then I copied the two lines, the “if” line and the “$redirect” line and then pasted them back in below the original. I then changed that user level from 0 to 1.

    Default users are, I believe a level 1, so zeros and ones now get redirected to the home page.

    That’s probably not the correct PHP way to do it, but it works.

    Hey, thanks, jweaks. I’ll give that a shot.

    Im pretty sure default users are a level 0, same as anonymous or unregistered users. Once you are a 1 you can actually do things beyond commenting, check the codex on user levels.

    I went through figuring all of that out setting up my login popup.

    On my site the default user level is 1. I think I caused it to be that way by changing the writing option to “May submit drafts for review.”

    I think that bumps new registrants up to 1 so they can submit. I’ll bet level 0 is the default at installation.

    If you change write permissions to “May publish…” I’ll bet the new user level goes up again. -jw

    Ok, I am trying to follow the suggestions here, but where exactly am I looking for line 178: $redirect_to = get_settings(‘siteurl’) . ‘/wp-admin/profile.php’;
    Is it in the main template, or somewhere else?

    I have done this for my local Taekwondo Club website. It’s really not a lot you will have to do and I have tried to be very specific documenting.

    See the step by step instruction at :


    Hope this is useful.

    This behaviour applies to almost all users except level 0s. To have it also for them just comment out the following line in wp-login.php:

    if ( 0 == $user->user_level )
    $redirect_to = get_settings(‘siteurl’) . ‘/wp-admin/profile.php’;

    I also wanted this functionality, but if you just hack the wp-login.php, users COULD still go to wp-admin (from the link on the site or by typing it in) so I wrote a short thing to plugin to auth_redirect() – so before it goes to any wp-admin page, so leave wp-login.php going there, and then this will redirect. I haven’t written any plugins before or know php really at all, but it works for me so Ill post it here. I had it so under user_level 2 goes directly to the site, and am using it on wordpress 2.0. So they never can edit/change their profile, this is just so I can give 10 friends the same user/pwd to read protected posts, I don’t need them able to change anything or see the dashboard.

    if ( !function_exists(‘auth_redirect’) ) :

    function auth_redirect() {
    // Checks if a user is logged in, if not redirects them to the login page
    if ( (!empty($_COOKIE[USER_COOKIE]) &&
    !wp_login($_COOKIE[USER_COOKIE], $_COOKIE[PASS_COOKIE], true)) ||
    (empty($_COOKIE[USER_COOKIE])) ) {

    header(‘Location: ‘ . get_settings(‘siteurl’) . ‘/wp-login.php?redirect_to=’ . urlencode($_SERVER[‘REQUEST_URI’]));
    else {
    if (!empty($_COOKIE[USER_COOKIE] )) {
    $user_login = $COOKIE[USER_COOKIE];
    $userdata = get_userdatabylogin($user_login);
    // If the user can’t edit posts, send them to site
    if ( !$userdata->user_level <= 2){
    header(‘Location: ‘ . get_settings(‘siteurl’) );


Viewing 15 replies - 1 through 15 (of 26 total)
  • The topic ‘change login redirect’ is closed to new replies.