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 7 years, 7 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

  • Issue with Page View Access for Non-Logged In Users
  • Can’t add an image using Divi
  • MonsterInsights access capacity for user role
  • Yoast Redirects Edit capability
  • Bulk-add user does not use user role of main site
  • Access only to edit Status within an Order?
  • Unable to grant access to Appearance > Customize
  • Additive roles
  • downgrade
  • Role editor widget has vanished from pages in admin

Recent Replies

  • [email protected] on Issue with Page View Access for Non-Logged In Users 2 days, 7 hours ago
  • [email protected] on Issue with Page View Access for Non-Logged In Users 2 weeks ago
  • Vladimir on Issue with Page View Access for Non-Logged In Users 2 weeks, 2 days ago
  • Vladimir on Can’t add an image using Divi 2 weeks, 3 days ago
  • [email protected] on Can’t add an image using Divi 2 weeks, 3 days ago
  • [email protected] on Can’t add an image using Divi 2 weeks, 4 days ago
  • Vladimir on Can’t add an image using Divi 2 weeks, 4 days ago
  • Vladimir on Can’t add an image using Divi 3 weeks ago
  • [email protected] on Can’t add an image using Divi 3 weeks ago
  • Vladimir on Can’t add an image using Divi 3 weeks ago
  • Contact Us
  • Privacy Policy
  • Terms of use (EULA)
© 2010 - 2025 Artellect Limited. Units A-C, 25/F., Seabright Plaza, No. 9-23 Shell Street, North Point, Hong Kong. Contact: hd@role-editor.com
Share