• Skip to primary navigation
  • Skip to main content

RocketGeek

Home of WP-Members, The Original WordPress Membership Plugin

  • WordPress Plugins
    • WP-Members
      • FAQs
      • Quick Start
      • Documentation
      • Extensions
    • Advanced Options
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Download Protect
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Invite Codes
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • MailChimp Integration
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • PayPal Subscriptions
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Salesforce Web-to-Lead
    • Security
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Text Editor
      • Purchase the Plugin
      • Get the Pro Bundle
    • User List
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • User Tracking
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Memberships for WooCommerce
    • WordPass
  • Blog
    • Basics
    • Tips and Tricks
    • Filters
    • Actions
    • Code Snippets
    • Shortcodes
    • Design
    • Release Announcements
  • Store
    • Cart
    • Checkout
  • Contact
  • Log In
  • Show Search
Hide Search
Home » Filters » Redirect a user on first login

Redirect a user on first login

Chad Butler · May 15, 2012 ·

This article is provided free. Find out how you can get full access to premium content, including how-to articles and support forums, as well as priority email support and member exclusive plugin extensions..

 

Suppose you have some information you want to direct first time users to, such as a rules page, or a list of certain posts, etc. You would like to do that the first time they login as a new user.  You can do that with the magic of the wpmem_login_filter. 

This first example is basic and will redirect a user to a page you define (where indicated in the code snippet comments).

add_filter( 'wpmem_login_redirect', 'my_first_login_redirect', 10, 2 );
function my_first_login_redirect( $redirect_to, $user_id ) {

    // Set page to redirect the user to.
    // @uses https://codex.wordpress.org/Function_Reference/home_url
    $redirect_url = home_url( 'my-page' );
    
    // See if the user has already logged in before
    // @uses https://codex.wordpress.org/Function_Reference/get_user_meta
    $first_login = get_user_meta( $user_id, 'first_login', true );
    if ( ! $first_login ) {
        // Sets that the user has done their first login
        // @uses https://codex.wordpress.org/Function_Reference/update_user_meta
        update_user_meta( $user_id, 'first_login', 'true' );
        
        // Set redirect based on user's first login
        $redirect_to = $redirect_url;
    }
    
    return $redirect_to;
}

The following example shows how to direct the user to the change password page if it is the first time they have logged in. (This assumes that you have a [wpmem_profile] page and that you have set the location of that page in the plugin’s settings for User Profile Page.)

add_filter( 'wpmem_login_redirect', 'password_change_login_redirect', 10, 2 );
function password_change_login_redirect( $redirect_to, $user_id ) {

    // Check for the presence of a flag if the user has logged in before.
    $first_login = wpmem_get_user_meta( $user_id, 'first_login' );

    // If the user has never logged in, do this:
    if ( ! $first_login ) {

        // Set that the user has logged in the first time.
        update_user_meta( $user_id, 'first_login', 'true' );

        // Return the user profile url for password change.
        return wpmem_profile_url( 'pwdchange' );
    }

    return $redirect_to;
}

Filters free, wpmem_login_redirect

Ready to get started?

Join Today!

© 2025 · butlerblog.com · RocketGeek is built using WordPress, WP-Members, and the Genesis Framework

  • butlerblog.com
  • WP-Members Support Subscription
  • Terms of Service
  • Privacy Policy
  • Refund Policy