This piece of code is trivial and very useful for development of custom sites and cms.
add to functions.php
add_filter('logout_url', 'projectivemotion_logout_home', 10, 2);
function projectivemotion_logout_home($logouturl, $redir)
{
$redir = get_option('siteurl');
return $logouturl . '&redirect_to=' . urlencode($redir);
}
Enjoy! Happy Coding!
- Amado Martinez / Projectivemotion Web Development
My name is Amado Martinez. I'm a 23 year old programmer living in Reynosa, Mexico. I specialize in website systems. I'm not a frequent blogger, but I hope that you find my web development tips helpful and perhaps even AWESOME! Thanks for visiting :)
How about changing the core file (wp-includes/general-template.php) to wp_logout_url( home_url() ) inside the wp_logout_url($redirect) function. In that way it always redirect to homepage whenever logout is triggered.
Hi. It’s not normally recommended to edit the wordpress include files directly because they can cause problems but more importantly because any time that you choose to update your installation there is a chance that your modification will be rewritten by any new code changes in the wordpress update. It’s better to use the functions.php file of your theme or create a custom plugin.
Hi, your piece of code was working good.
HOW ABOUT WRONG LOGIN CREDENTIALS?
Do you also have a code that redirect to a page and give a message?
Hope to be in Mexico next month. To cold here in Europe!
Hi Martin. I know this is a bit late but I published a post regarding redirection after invalid login. Check it out http://projectivemotion.com/2011/12/16/redirect-failed-login-attempt-wordpress/
Hope you’re enjoying the weather wherever you are ! lol
Thanks! When I add this code to functions.php in my localhost instance, it works perfectly. However, in production site, behavior remains unaltered. What could I be missing?
cheers for the easy hook/function. and i agree, easier to adjust the functions and leave as much as you can in one page because inevitably when we go back and try and find what we adjusted its a nightmare if we tried adjusting the actual code directly within the wp functions. been there done that!
yes i am using this code. it works perfectly
What a friggin lifesaver. Thanks!
Than You very Much!
Thanks its really helpful