WordPress.org

Support

Support » How-To and Troubleshooting » How to control what page to display after logging in?

How to control what page to display after logging in?

Viewing 7 replies - 1 through 7 (of 7 total)
  • 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.

    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.

    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();
                }
         }
    }

    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.

    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.

    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

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

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to control what page to display after logging in?’ is closed to new replies.
Skip to toolbar