Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

On my website I have removed wp-login.php to disable the login from default wordpress login window. Then I installed Social Login plugin, users are able to Login properly by using this plugin. But if they click on Logout button, they will be taking to the 404 page, since Logout URL is nothing but a parameter pass to wp-login.php page. So please suggest me a solution, where I can use wp-login.php page only for Logout process. Login and Password Reset should not work.

Sorry for the lengthy query, but I am in urgent need. Thanks in advance.

share|improve this question
    
Do they successfully log out before redirecting to 404 page? –  Rahil Wazir Jan 12 at 18:54
    
@RahilWazir: No, they don't. If they click browser back button and do the refresh they can see dashboard as is. –  Hrishi Jan 12 at 18:59

1 Answer 1

WordPress has hooks so you don't need to actually remove wp-login.php. login_head fires before any HTML is rendered for the login form, and wp_logout fires after the login session has been destroyed. You can put this code in a custom plugin or in your theme's functions.php file to let logout requests continue working but block everything else.

// Allow logout actions but redirect to the home page for all other wp-login.php requests
add_action( 'login_head', 'redirect_home_on_login_form' );
function redirect_home_on_login_form() {
    if ( ! isset( $_REQUEST['action'] ) || 'logout' !== $_REQUEST['action'] ) {
        wp_redirect( home_url( '/' ) );
        exit();
    }
}

// wp_logout fires after the user's login cookies have been removed
add_action( 'wp_logout', 'redirect_home_on_logout' );
function redirect_home_on_logout() {
    wp_redirect( home_url( '/' ) );
    exit();
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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