• Resolved Tom

    (@tomhargreaves)


    Hi there,

    I have Theme My Login installed. Once I have logged in, if I visit http://mysite.com/login again it shows the “Welcome, Xxx” with gravatar and links to dashboard etc. This is also the case with the /register page.

    Rather than do this, I would prefer it to re-direct me back to the homepage when logged in. How can I achieve this?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Jeff Farthing

    (@jfarthing84)

    Create wp-content/plugins/theme-my-login-custom.php:

    <?php
    
    function redirect_tml_pages() {
        $tml = theme_my_login()->get_object();
    
        if ( is_user_logged_in() as $tml->is_tml_page( array( 'login', 'register' ) ) {
            wp_redirect( home_url() );
            exit;
        }
    }
    add_action( 'template_redirect', 'redirect_tml_pages', 20 );
    
    Thread Starter Tom

    (@tomhargreaves)

    thanks for the reply here. unfortunately when i added this it didn’t work.

    i managed to find a solution elsewhere though, so thought i’d follow-up in case anyone else wanted to do the same thing:

    add_action('wp', 'add_login_check');
    function add_login_check()
    {
        if ( is_user_logged_in() && is_page( [6070, 6071, 6072, 6073] ) ) {
            wp_redirect('http://my_homepage_url');
            exit;
        }
    }

    add this to your wordpress functions.php file.

    you then need to replace the 6070, 6071, 6072, 6073 numbers to whatever the page IDs are for your login, register, lostpassword and resetpass pages (these can be found in the URL when editing the page).

    and finally you can change the wp_redirect('http://my_homepage_url'); to whatever webpage you want the users to be redirected to.

    • This reply was modified 6 years, 6 months ago by Tom.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Redirect when accessing /login when logged in’ is closed to new replies.