WordPress (always) redirect to homepage after logout.

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


  1. 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.

  2. Hi, your piece of code was working good.
    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!

  3. 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?

  4. 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!

  5. yes i am using this code. it works perfectly

  6. What a friggin lifesaver. Thanks!

  7. Than You very Much!

  8. Thanks its really helpful 🙂

  9. Couldn’t agree more – “very useful for development”! 🙂

  10. I added this code to the functions.php file of my theme, at the end of the file, but it doesn’t work? What am I doing wrong?

Leave a Reply

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