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, 1 month 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

  • Cannot edit LearnDash Course Permalinks
  • I have enabled all options for a CPT but my user cannot add a new one
  • Main category is deleted each time a specific role updates a post.
  • Restrict files in Media Library to Subscriber role or higher
  • Cannot edit LearnDash Course Permalinks
  • “Administrator” role missing under multisite’s subsite’s Users menu item
  • Can’t add categories to post
  • Need to create a Read Only User
  • How to restrict specific settings within a wordpress plugin
  • Membership plan

Recent Replies

  • Gracie Vaughn on Gravity Forms Restrictions No Longer Working 21 hours, 6 minutes ago
  • Vladimir on I have enabled all options for a CPT but my user cannot add a new one 4 days, 4 hours ago
  • highprrrr on I have enabled all options for a CPT but my user cannot add a new one 4 days, 19 hours ago
  • epss on Gravity Forms Restrictions No Longer Working 6 days, 16 hours ago
  • TomJaycocks on Can’t add categories to post 6 days, 16 hours ago
  • Vladimir on Main category is deleted each time a specific role updates a post. 6 days, 20 hours ago
  • James Smith on Gravity Forms Restrictions No Longer Working 6 days, 21 hours ago
  • Mike on Restrict files in Media Library to Subscriber role or higher 1 week ago
  • Vladimir on Restrict files in Media Library to Subscriber role or higher 1 week ago
  • Vladimir on Can’t add categories to post 1 week ago
  • Contact Us
  • Privacy Policy
  • Terms of use (EULA)
© 2010 - 2022 Artellect Limited. Units A-C, 25/F., Seabright Plaza, No. 9-23 Shell Street, North Point, Hong Kong. Contact: hd@role-editor.com
Share