Skip to content Skip to main menu
User Role Editor
Menu
  • Home
  • Prices
  • Download
  • Testimonials
  • Forums
  • Blog
  • ChangeLog
  • Documentation
  • Login
Home › Topic › How do I redirect a subscriber to XYZ page after login?

Change WordPress user roles and capabilities › Forums › How to or FAQ › How do I redirect a subscriber to XYZ page after login?

Tagged: redirect user, subscriber login

  • This topic has 4 replies, 3 voices, and was last updated 4 years, 10 months ago by geoweb1.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • 23/03/2016 at 21:21 #2160
    jodyshockley
    Participant

    Hello,

    After user registration, my subscribers are redirected to the homepage via the user reg. Howver, when they come back to the site, login, they are redirected to the WordPress Dashboard. I’d like them to redirect to the homepage. This would be nice to see in a future version of your plugin for easy handling (and perhaps different user types are redirected to different pages?).

    24/03/2016 at 00:46 #2162
    Vladimir
    Keymaster

    Hi,

    It may be useful to add a user interface for this feature. Thanks. I will consider to add this functionality to one of a future versions.

    Currently may add a code to the functions.php file:
    https://codex.wordpress.org/Plugin_API/Filter_Reference/login_redirect

    03/05/2018 at 03:46 #4819
    geoweb1
    Participant

    Hi Vladimir.

    Can you please post the code to redirect all users to the home page, except for admin?

    Thank you!

    03/05/2018 at 04:34 #4822
    Vladimir
    Keymaster

    Hi,

    Try this variant:

    
    /**
     * Redirect to the home page all users except administrator after successful login.
     *
     * @param string $redirect_to URL to redirect to.
     * @param string $request URL the user is coming from.
     * @param object $user Logged user's data.
     * @return string
     */
    
    function my_login_redirect( $redirect_to, $request, $user ) {
        //is there a user to check?
        if (isset($user->roles) && is_array($user->roles)) {
            //check for subscribers
            if (!in_array('administrator', $user->roles)) {
                // redirect them to another URL, in this case, the homepage 
                $redirect_to =  home_url();
            }
        }
    
        return $redirect_to;
    }
    
    add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
    
    03/05/2018 at 22:49 #4831
    geoweb1
    Participant

    Works great, thank you!!

  • Author
    Posts
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Log In

Recent Topics

  • Admin lost access to Plugin User Role Editor
  • Hide `+ Add new category`
  • License Key Field is missing
  • Block Content View Restrictions on Categories and Tags for Editor role
  • Content restriction redirect to 404 not working
  • Allow certain user roles to upload non-default files
  • Ugly menu access option display if css class or link relationship is visible
  • Allowing non-admins to manage custom type taxonomies/categories
  • Restricting Learndash content types
  • Edit administrator capabilites return 404

Recent Replies

  • Vladimir on Admin lost access to Plugin User Role Editor 8 hours, 19 minutes ago
  • Vladimir on Admin lost access to Plugin User Role Editor 8 hours, 19 minutes ago
  • Vladimir on Block Content View Restrictions on Categories and Tags for Editor role 2 days, 18 hours ago
  • Vladimir on Allowing non-admins to manage custom type taxonomies/categories 2 days, 18 hours ago
  • Vladimir on Hide `+ Add new category` 2 days, 19 hours ago
  • Vladimir on License Key Field is missing 4 days, 8 hours ago
  • edering on License Key Field is missing 4 days, 10 hours ago
  • Vladimir on License Key Field is missing 4 days, 20 hours ago
  • Vladimir on Allow certain user roles to upload non-default files 1 week ago
  • Vladimir on Allow certain user roles to upload non-default files 1 week ago
  • Contact Us
  • Privacy Policy
  • Terms of use (EULA)
© 2010 - 2023 Artellect Limited. Units A-C, 25/F., Seabright Plaza, No. 9-23 Shell Street, North Point, Hong Kong. Contact: hd@role-editor.com
Share