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

  • Role editor widget has vanished from pages in admin
  • Issue with Image Insertion in Posts – User Role Editor Pro
  • Item not available in Admin Menu
  • Restrict by Taxonomy, but Allow Access to all Taxonomy Items
  • Editor role – Siteground Speed Optmiser – Flush Cache
  • Editor Access to Appearance / Menus
  • WP Version 6.8 – Text Domain Error
  • Prevent Unauthenticated Access to CPT by Default
  • Other roles not restricted
  • Admin not having WP backend menu items

Recent Replies

  • [email protected] on Item not available in Admin Menu 1 month, 2 weeks ago
  • Vladimir on Item not available in Admin Menu 1 month, 2 weeks ago
  • VC Team on Admins can’t see new CPTs 1 month, 2 weeks ago
  • Stephen001 on Editor Access to Appearance / Menus 1 month, 4 weeks ago
  • Vladimir on Editor Access to Appearance / Menus 1 month, 4 weeks ago
  • Vladimir on WP Version 6.8 – Text Domain Error 2 months, 2 weeks ago
  • Vladimir on WP Version 6.8 – Text Domain Error 2 months, 2 weeks ago
  • camber799 on Prevent Unauthenticated Access to CPT by Default 2 months, 4 weeks ago
  • Channel Digital on Multisite – Capabilities reset when restricting access to a plugin 3 months, 2 weeks ago
  • Channel Digital on Multisite – Capabilities reset when restricting access to a plugin 3 months, 2 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