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.




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.
This only works in the case of a /wp-admin login and not for a front-end form or am i missing something?
Perfectly, the particular submit can be a most up to date topic
on this windows registry linked problem. I personally
remain in a person’s a conclusion and will thirstily look forward to your current returning messages. Only announcing thank you won’t be adequate,
for that unparalleled lucidity in the composing.
I’ll right away take hold of a person’s feed to remain abreast of any kind of improvements.
What if I brought in a user from a different website (sister site) and wanted them to login via wordpress, then be redirected depending on a variable, like this:
MyWordpressSite.com/wp-login.php?redirect=ThisVariable
How do I do this?