[Login Redirect] Logged-in user issue

Dear team

We use the plugin WP User Manager and would like to know how to redirect a user who is already LOGGED IN if he ends up on the login page again. Currently the user sees a page saying that he is logged in followed by his name. We have found a similar issue, but not quite what we are after:
https://premium.wpmudev.org/forums/topic/redirect-when-user-is-logged-in
Our login is not on the homepage and only appears once he's checking out. Hence we would like to redirect any client to the cart in case he is already logged in. Please let us know what coded needs to be added to the functions.php file. Thanks for the support.

Best regards,
Fabrizio

  • viobru

    Hi, Fabrizio!

    Hope you’re doing great and thanks for contacting us :slight_smile:

    I’ve registered a test account on your site to check the exact page that you’re referring to and I’ve found that it has the ID 38, as you can see in this screenshot:

    So I would suggest that you use the code that my teammate Luís provided in the other thread just changing the homepage for this other page. It would go like this:

    function redirect_my_page()
    {
    	global $current_user;
    
        if ( is_user_logged_in() && ( is_page( 38 ) ) )
        {
            wp_redirect('http://example.com/'); 
    
            exit;
        }
    }
    add_action('template_redirect', 'redirect_my_page');

    This code should be placed in your theme’s file functions.php (or using a mu-plugin) and you should replace "'http://example.com/" with the desired page URL.

    Please, let us know if it worked :slight_smile:

    Kind regards,

    Violeta

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.