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 🙂

Leave a Reply

Are you looking for support?

Please ask support questions in BuddyDev Forum and help us serve you better. Please use comment for general discussion/feature suggestions.

Your email address will not be published. All the fields marked as * are required.

If you are posting code, please use <pre> { Your Code Block } </pre>. Example:- <pre> echo $name; </pre>

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">