Posted in WordPress · October 16th, 2011 by Kazim · Comments (0)
By the project, I had to redirect the user after login. I wasn’t able to find a perfect code. There Peter’s Redirect Plugin didn’t work for me in latest version of WordPress. I tried to do it a lot hence wasn’t able to. Obviously no one would like to mess with WordPress core for doing it, neither me. I managed to use it through login redirect filter (Check Plugin API Filter Reference). The page is marked incomplete and asking to contribute, however the function works perfect. Following is your piece of cake for how to redirect after login in WordPress.
add_filter('login_redirect', 'redirectlogin'); function redirectlogin($redirect_to, $url_redirect_to = '', $user = null) { return 'http://www.somesite.com'; }
You can insert this code into functions.php file either your plugin or where ever required to redirect after login. You’re free to expand the code. Changing the return value to / will let you redirect to the home page. To redirect the user within the site you can simply use /page-slug.
The other way to redirect was through URL wp_login_url.
echo wp_login_url('http://www.somesite.com');
It didn’t work for me as well. This just simple echo the url which contains the redirect variable and the mean url to its value.
Hope you find it useful, let me know if we can improve or use another code instead here.
No comments yet