WordPress.org

Forums

How to control what page to display after logging in? (8 posts)

  1. nmmedina
    Member
    Posted 3 years ago #

    I'm using the Login widget that comes with default page. After a Subscriber user logs in, I expect the user to be sent back to either the page he was on or some other page of my website. Instead, the user profile page appears with the dashboard link listed to the left of the screen. None of my users would expect this. Some won't know how to get out of this screen (seniors) and I just don't want them there.

    Don't know what other information you may need.

    Thanks.

  2. Mat Lipe
    Member
    Posted 3 years ago #

    Here is a nice little function that you could add to your child theme's functions.php file.

    add_filter("login_redirect", "custom_login_redirect", 10, 3);

    function custom_login_redirect($redirect_to, $request, $user){
    //is there a user to check?
    if(is_array($user->roles)){
    //check for admins
    if(in_array("administrator", $user->roles)){
    return home_url("/wp-admin/");
    }else{
    return home_url();
    }
    }
    }
    `
    This will redirect all non admins to the homepage after they login. Let me know if you need any other customization done to it.

    Hope this helps.

  3. nmmedina
    Member
    Posted 3 years ago #

    Thanks Mat,

    I forgot to mention I'm new at this at can't figure out how to get to the "child theme's functions.php file".

    Also, once there, do I add both the function call and function at the end of the file? Thanks.

  4. Mat Lipe
    Member
    Posted 3 years ago #

    What is the address of your site? I can let you know where you functions.php file is from there.

    Once there you will want to add the entire

    add_filter("login_redirect", "custom_login_redirect", 10, 3);
    
    function custom_login_redirect($redirect_to, $request, $user){
          //is there a user to check?
         if(is_array($user->roles)){
               //check for admins
               if(in_array("administrator", $user->roles)){
                    return home_url("/wp-admin/");
                }else{
                     return home_url();
                }
         }
    }
  5. nmmedina
    Member
    Posted 3 years ago #

    my website is "http://www.hamiltonvoices.com/"

    I'm only starting so nobody is using it. I need to make the Home page static and make the blog available after logging in in a separate page; and add a way for the user to register. But, one step at a time.

    Thanks.

  6. Mat Lipe
    Member
    Posted 3 years ago #

    You will find you functions.php file at
    /wp-content/themes/twentyeleven/functions.php

    The safest place to add the functions is at the bottom of the page.
    Hopefully this works for you. I will be happy to help you tweak it if need be.

  7. nmmedina
    Member
    Posted 3 years ago #

    I imgagine you mean
    http://www.hamiltonvoices.com/wp-content/themes/twentyeleven/functions.php

    or

    http://www.hamiltonvoices.com/wp-admin/wp-content/themes/twentyeleven/functions.php

    I get this error:

    Fatal error: Call to undefined function add_action() in /hermes/bosweb/web226/b2265/ipg.nmedinadesigncom/hamilton/wp-content/themes/twentyeleven/functions.php on line 50

  8. nmmedina
    Member
    Posted 3 years ago #

    It worked. I figured out where the file was and it's working good now. Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags