4

I have a couple issues with the way Wordpress handles redirects on login and logout.

Standard behaviour is:

login: /wp-login.php (with no redirect_to url) -> /wp-admin.php 
logout: /wp-admin.php -> /wp-login.php

What want is:

login: /wp-login.php (with no redirect_to url) -> homepage
logout: /wp-admin.php -> homepage

Would prefer a coded solution please. It helps me to learn and understand how Wordpress works.

Thank you

3

This really does belong in a plugin, but you can just as easily drop it in your theme's functions.php

function default_login_redirect( $redirect, $request_redirect )
{
    if ( $request_redirect === '' )
        $redirect = home_url();
    return $redirect; 
}
add_filter( 'login_redirect', 'default_login_redirect', 10, 2 );
  • No worries. It's going into a custom plugin. Thanks. – EddyR Jan 13 '12 at 13:36
  • That worked. Those filters are hard to find sometimes :) – EddyR Jan 13 '12 at 13:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.