WordPress.org

Ready to get started?Download WordPress

Forums

WP-Members
[resolved] Redirect if ALREADY logged in (3 posts)

  1. BitBug
    Member
    Posted 8 months ago #

    First and foremost, thank you for a wonderful plugin. Very useful and very deep in its abilities.

    I'm using WordPress with WP-Members within a section of an existing website. I have the WordPress front page as a login page that uses the WP-Members short codes:

    [wp-members page="login"]
    [wp-members page="password"]

    I have used the WP-Members login filter and function redirect successfully for when someone logs in redirecting them to the Posts page.

    However, if someone is already logged in from a previous session and goes to the front page, the redirect does not recognize them as logged in and redirect them. I assume this might have to do with the filter and function not being called until someone logs in?

    My skills at coding are good, but I am relatively new to WordPress. Does anyone know how I can go about having WP-Members check if someone is already logged in, and if so redirect them?

    Assistance is greatly appreciated! Thanks!

    http://wordpress.org/plugins/wp-members/

  2. Chad Butler
    Member
    Plugin Author

    Posted 8 months ago #

    You can use is_user_logged_in for that.

  3. BitBug
    Member
    Posted 7 months ago #

    Thank you Chad, that led me down the right path.

    For those interested, the full solution was to put the following code in the header.php. I put mine right above the HTML5 declaration.

    <?php
    if (is_user_logged_in() && is_front_page() ) {
    wp_redirect('domain.com/pageToRedirectTo');
    exit;
    }
    ?>

    So the If statement checks if the user is logged in AND if they are on the front page of the site (which in this case is the login page for WP Members). If they are, then it redirects them to the page specified with my placeholder code of 'domain.com/pageToRedirectTo'

Reply

You must log in to post.

About this Plugin

About this Topic