WordPress.org

Ready to get started?Download WordPress

Forums

Redirect to blog after login (14 posts)

  1. Daddio
    Member
    Posted 10 years ago #

    Hi. I'm trying to figure out how to get the login process to redirect directly to the blog after a registered user logs in. I've tried a couple of different things in wp-login.php, but they usually break the process, and never actually let me get from the blog to the login page. I've been reading the forums, and haven't seen anything about this. Is there a hack or mod (or an idea) for how to do this that I have not seen? Thanks...

  2. carthik
    Member
    Posted 10 years ago #

    A problem you could face with redirecting folks to the index.php page after the login is that there is no link on the plain vanilla index.php to the admin interface page.

  3. skippy
    Member
    Posted 10 years ago #

    See my revision to my original post: it's line 301, not line 95.
    Line 301 is actually the "then" part of an if..then clause. Here's the if part, just above line 301:

    <?php if (isset($HTTP_GET_VARS["redirect_to"])) { ?>
    <input type="hidden" name="redirect_to" value="<?php echo $HTTP_GET_VARS["redirect_to"] ?>" />
    <?php } else { ?>
    <input type="hidden" name="redirect_to" value="wp-admin/" />
    <?php } ?>

    When I changed line 301 to redirect to index.php instead of wp-admin, my index's "login" link took me to the admin page.

  4. Daddio
    Member
    Posted 10 years ago #

    Skippy, thank you! That is absolutely what I was looking to make happen! I guess I missed that part of the code when I was looking through. Thanks again!
    2fargon, you're correct - the "logged in" user won't be able to post, but that is exactly what I am looking for with this particular blog. This one is my ramblings, just a personal/family informational kind of thing.
    Thanks again for the help!

  5. HardinComp
    Member
    Posted 9 years ago #

    Is that line 301 of root/wp-login.php, Skippy? My file only goes to line 254 and I don't want to put the code in the wrong place. I'm running WP 1.5.1.3.

  6. chrissearle
    Member
    Posted 8 years ago #

    In 1.5.2 wp-login.php reads

    $redirect_to = 'wp-admin/';

    I changed it to

    $redirect_to = '/';

    since my WP install is installed on the web-root and this works fine.

    From reading the code - setting the request parameter "redirect_to" from the login link should work without editing the wp-login file (so I thought maybe we could do this in the template instead of editing core wp files). However - the links I have are created by the wp_loginout function which takes no parameters - so I don't think it can easily be set.

  7. chrissearle
    Member
    Posted 8 years ago #

    Oops - forgot the line number - in mine - wp-login.php line 165

  8. theillustratedlife
    Member
    Posted 8 years ago #

    To get mine to work, I had to change this in wp-login.php:

    if ($user_login && $user_pass) {
    $user = get_userdatabylogin($user_login);
    if ( 0 == $user->user_level )
    $redirect_to = get_settings('siteurl') . '/';

    That last line used to redirect to /wp-admin/profile.php. This way, if a reader logs in, they get the main site. If I log in, I get the admin backend. If they need to change their profile, they can still clikc the Admin link after they login to get back to the backend.

    Not bad for someone who doesn't know shit about php. =)

  9. RavanH
    Member
    Posted 8 years ago #

    Tip for anyone who can use this:

    On WP2 I use the following methode to redirect users back to the same page they came from. So not coursly to the indexpage when logging in from a subpage, category page or post.

    Instead of using the standard <?php wp_loginout(); ?> in the sidebar.php of my theme, I defined the following bit that dispayes a standard text for visitors-not-logged and some links for logged-users:


    <h3>My Menu</h3>
    <?php global $user_identity, $user_level; get_currentuserinfo(); if (!$user_identity) { ?>
    <!-- put text for not logged visitors here -->
    <a href="<?php bloginfo('url'); ?>/wp-login.php?redirect_to=<?php echo get_permalink(); ?>">Login</a>
    <?php ; } else { printf(__('<p class="searchinfo">Welcome, <strong>%s</strong>.
    '), $user_identity); ?>
    <a href="<?php bloginfo('url'); ?>/wp-admin/profile.php">My Profile</a>
    <a href="<?php bloginfo('url'); ?>/wp-admin/profile.php?page=subscribe2/subscribe2.php">My Subscribtions</a> <!-- link to Subscribe2 plugin by Skippy -->
    <?php if ($user_level > 1) { wp_register(); }?>
    <a href="<?php bloginfo('url'); ?>/wp-login.php?action=logout&amp;redirect_to=<?php echo get_permalink(); ?>">Logout</a>
    <?php } ?>

    It needs adaptation for any perticular theme (like putting in unordered list and list item tags) but this might give some an idea about what can be done...

  10. pandem
    Member
    Posted 8 years ago #

    RavanH, thanks a lot for sharing your solution. I've looking for it several hours.

    Here's the code I added to redirect users to the homepage as well:

    if (is_home()) {
    $redir = get_settings('home');
    } else {
    $redir = get_permalink();
    }
    if (!$user_identity) { ?>
    <!-- put text for not logged visitors here -->
    <a href="<?php bloginfo('url'); ?>/wp-login.php?redirect_to = echo $redir; ?>">Login</a>

    etc.

  11. TomJohnson
    Member
    Posted 8 years ago #

    Is there any way to direct users to the Admin > Write > Post page rather than Admin > Dashboard after they log in?

  12. pandem
    Member
    Posted 8 years ago #

    After some research, and just in case someone is interested, I've improved my code by changing the first part from this:

    if (is_home()) {
    $redir = get_settings('home');
    } else {
    $redir = get_permalink();
    }

    to this:

    if ((is_home()) && !($_SERVER['QUERY_STRING'])) {
    $redir= get_settings('home');
    } else {
    $redir= get_settings('siteurl') . $_SERVER['REQUEST_URI'];
    }

  13. 34k
    Member
    Posted 8 years ago #

    As an addition to chrissearle's info since I don't want my users to see the login screen unless they are trying to login, I changed my WP 2.0.1 wp-login.php thusly:

    line 28: $redirect_to = '/';
    line 239: <input type="hidden" name="redirect_to" value="/" />

    Users are always redirected to the home page after login and logout.

  14. firesnake
    Member
    Posted 7 years ago #

    I just used find and searched for $redirect_to in wp-login.php and replaced every instance of wp-admin with index.php. (My index.php is in my wordpress root.)

    It doesn't seem broken yet.

Topic Closed

This topic has been closed to new replies.

About this Topic