BuddyDev

BuddyPress Tutorial: Redirect users on their first login

Want to redirect users on their first login to some specific page on a BuddyPress site? This tutorial is your guide to login redirection.

Let us see a few reasons why you might want to redirect your users on their first login.

  • You may want to help them understand  site features by sending to some guide page
  • You may want to send them to their profile
  • You may want to send them to some twitter like friends suggestions/group suggestions page.
  • … and you may have some other better reason to do so.

Once we agree that user should be redirected to somewhere, We need to add the code to our functions.php in theme or bp-custom.php

WordPress provides a filter "login_redirect" which allows us to change the url where the user should be redirected after login. You can do a lot of fun stuff with this filter. You can redirect users to different urls  by their member type or roles or geo location or some other criteria as you please.

For this tutorial, our only concern is first login of the user.

Strategy:- Detecting first login of the user

BuddyPress stores user's last active time if they have logged in to the site before.

From the above statement, we can safely deduce that if the last active time of the user who is logging in is empty, it must be their first login.

Here is an example code to redirect user to their BuddyPress profile on first login

 

That's all. Have fun building your BuddyPress community 🙂

2 Responses to BuddyPress Tutorial: Redirect users on their first login