nSurface

Redirect to the WordPress homepage after login

Normally after you log into your wordpress site you are directed to the admin dashboard. WordPress assumes that if you log in, that you must want to edit the site somehow. This is probably true in most cases. But in the recent past I’ve been making more and more themes that are private and/or collaborative serving a wide range of people from the computer savvy to near Luddites. Something I heard a lot goes something like: ‘when I log in I get forwarded to some other website and I don’t know how to get back!’. What is this ‘other website’? It turns out it’s the admin dashboard, and it freaks a lot of people out apparently (and can potentially set your computer on fire according to claims). Anyway, there are a lot of reasons you might want to forward your users on to something other than the admin page when they log in, like if you have a private blog and your family has the password to it and they have no reason to see the dashboard (since they don’t even have permissions to create/edit content anyway). Paste this into your functions.php file:


/* login redirect to index page */
function redirect_to_front_page() {
 global $redirect_to;
 if (!isset($_GET['redirect_to'])) {
 $redirect_to = get_option('siteurl');
 }
}
add_action('login_form', 'redirect_to_front_page');

This function will redirect to the home url by default, but with minimal modification you can redirect anywhere you see fit.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>