Skip to:
Content
Pages
Categories
Search
Top
Bottom

Redirect users to their notifications after login

  • @jessicana

    Participant

    Hello,

    I want to redirect users to their unread notifications page after they sign in. How can we achieve this?
    The link is: http://www.DOMAINNAME.com/members/USERNAME/notifications/

    I use this code to redirect to homepage but I prefer the notifications.

    function admin_default_page() {
      return '/home';
    }
    
    add_filter('login_redirect', 'admin_default_page');

    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • @shanebp

    Moderator

    Try:
    return bp_loggedin_user_domain() . 'notifications/';

    @jessicana

    Participant

    This did not work. It simply redirects to:
    http://www.DOMAINNAME.com/notifications/

    404 Error page

    @shanebp

    Moderator

    Try this:

    function jessicana_redirect_page( $redirect_to, $request, $user ) {
        $redirect_to = bp_core_get_user_domain($user->ID) . 'notifications/';
        return $redirect_to;
    }
    add_filter('login_redirect', 'jessicana_redirect_page', 11, 3);

    @jessicana

    Participant

    This is a killer code 🙂
    Yes it worked darling

    @jessicana

    Participant

    One more question. What if I want users who logs in using the sidebar widget to return to the same page where they were while I want users who logs in using homepage link to be directed to their notifications page?

    @jessicana

    Participant

    In other way, I will be using this code for the whole site except login widgets (like BBpress log in sidebar widget):

    function jessicana_redirect_page( $redirect_to, $request, $user ) {
        $redirect_to = bp_core_get_user_domain($user->ID) . 'notifications/';
        return $redirect_to;
    }
    add_filter('login_redirect', 'jessicana_redirect_page', 11, 3);

    For widgets, I need a different function that redirects to the same page where users logs from. Is this possible?

    I appreciate the help

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Redirect users to their notifications after login’ is closed to new replies.
Skip to toolbar