A common question I’ve seen is how can you redirect a user to a specific URL after they login to WordPress. Maybe you want to hide the Admin Dashboard from your users, so redirecting them to the home page after logging in is a great way to do this. Just place the below code in your themes functions.php file:
<?php
add_action('login_form', 'redirect_after_login');
function redirect_after_login() {
global $redirect_to;
if (!isset($_GET['redirect_to'])) {
$redirect_to = get_option('siteurl');
}
}
?>
The preceding code snippet will redirect any user who logs in to the home page (siteurl) of WordPress. You can easily set any redirect URL you want by changing the value of the $redirect_to variable. This function also verifies that the redirect_to querystring doesn’t exist before setting the redirect URL.
It’s as easy as that! Now you can easily control where your users are redirected to when they login to WordPress.
Related posts:
- How To: Load User Info Using the Admin Email in WordPress
- How To: Hide an Admin Menu in WordPress
- How To: Remove Default Profile Fields in WordPress
- How to: 301 Redirect from one domain to another using mod_rewrite
- How To: Create Backdoor Admin Access in WordPress




What about redirecting based on user roles?
Let’s say you want those with the user role “Author” and above to be redirected to the backend while “Subscribers” should be redirected to the home page?
you need a plugin for that you will get that plugin from there http://wordpress.org/extend/plugins/peters-login-redirect/
Thanks, with this little tweak my site is totally user friendly.
I have on my site links to differing parts based on user roles. So my subscribers just get access to their profile, and myself acess to the dashboard etc. The links are not visable till the person is logged in.
The code is such:
= 1 ) : ?>
<a href="/wp-admin/”>Dashboard
<a href="/wp-admin/post-new.php”>Submit post
= 1 ?>
<a href="/wp-admin/profile.php”>Profile
<a href="” title=”Logout”>Logout
I was also wondering if it is possible that after someone logs into wordpress it just goes to the page before they logged in. So whatever page they were on before they went to the login page, they would go back to that.
Very useful though. My only reason is using the multisite, some people are so deep in their blogs it would be annoying to have them start at the main page again.
Thanks, I just copied and pasted it, it was that easy. Plus it’s upgrade proof too. Saved me quite a bit of hassle, cheers.