Skip to content
ProfilePress
  • Features
  • Addons
  • Pricing
  • Support
    • Contact Us
    • Documentation
    • Blog
  • Account
  • Buy Now
ProfilePress
  • Features
  • Addons
  • Pricing
  • Support
    • Contact Us
    • Documentation
    • Blog
  • Account

Home » ProfilePress Tutorials » WordPress User Redirection After Social Login Based on Roles

WordPress User Redirection After Social Login Based on Roles

Last Updated on October 1, 2021

In this tutorial, I will be sharing a code snippet that will redirect users to a custom WordPress page or URL based on their assigned role after they successfully log in to your via ProfilePress social login.

Note: the code should be pasted to your theme’s functions.php file or your site-specific / dummy plugin.


add_filter('ppress_social_login_redirect', 'ppress_social_login_redirect_by_role', 10, 3);

function ppress_social_login_redirect_by_role($url, $social_network, $user_id)
{
    $a = get_user_by('id', $user_id);
    //retrieve the user roles
    $user_roles = $a->roles;

    /**
     * we'll redirect users with student role to https://xyz.com/student/
     * and those with teacher role to https://xyz.com/teacher/
     */
    if (in_array('student', $user_roles)) {
        $url = 'https://xyz.com/student/';
    } elseif (in_array('teacher', $user_roles)) {
        $url = 'https://xyz.com/teacher/';
    }

    return $url;
}

Code Explanation

What the code above does is, check the role of the user logging in. If the user is a student (i.e. has a “student” role), they get redirected to https://xyz.com/student/ and if a teacher (with “teacher” role), they are redirected to https://xyz.com/teacher/

To include more user role check and login redirection, create an additional `elseif` conditional block for them and include it in the above code.

If you have any pre-sale question, inquiring or contribution, please get in touch.

Create Paid Membership Websites in Minutes

Install ProfilePress today and get a modern and powerful WordPress membership & ecommerce website – the easy way!

Get ProfilePress Membership Plugin
Newsletter Subscription
Helpful articles and promos. Unsubscribe any time.

Subscribe to our email list now!

We promise not to spam you. You can unsubscribe at any time.
Invalid email address
Thanks for subscribing!

Featured Tutorial

  • Creating Membership Plans in WordPress - Easy Guide
  • How to Create WooCommerce Membership Website - Full Guide
  • Subscription Management by Customers
  • Selling Files (Digital Downloads & Products) on WordPress
  • Setting Up Paddle Payment Method
  • PHP Code Snippet: Check if user has an active subscription
  • How to Create a WordPress User Directory Page
  • Building a WordPress Member Directory Page

Create Paid Membership Websites

Install ProfilePress today and get a modern and powerful WordPress membership & ecommerce website.

Get Started

Links

Login
Blog
Pricing
Addons
Try Live Demo
Request Support
Affiliate Program
Changelog
Documentation
Partners

Top Features

Create Membership Sites
WooCommerce Memberships
Sell Digital Product
Custom Registration & Login
Member Directory
Content Protection
User Moderation
Social Login
Metered Paywall
Invite Codes

Our Brands

MailOptin
FuseWP
CrawlWP
FeedbackWP

About Us

ProfilePress Exclusive

Education Blogging Ideas!

Receive top education news, lesson ideas, teaching tips and more!

Invalid email address
We promise not to spam you. You can unsubscribe at any time.
Thanks for subscribing!
X-twitter Youtube
Copyright © 2026 Proper Fraction LLC.
ProfilePress™ is a trademark of Proper Fraction LLC.
Terms & Conditions · Privacy Policy
X icon to X close optin popup
Download ProfilePress Plugin

Enter your email and submit to receive a link to download the WordPress plugin.

We promise not to spam you. You can unsubscribe at any time.
Invalid email address
Please check your email for the plugin download link.