skip to Main Content

WordPress Login and Logout quick fixes

Ever wanted how to redirect user to your login page instead of wp-login.php login page? And did you ever want to wordpress loginredirect user to the same login page when they logout?

Well the first set of codes show how to redirect logins with error to the same page with nothing to change.

//if login fails, redirect to current page
add_action( 'wp_login_failed', 'my_front_end_login_fail' ); // hook failed login
function my_front_end_login_fail( $username ) {
$referrer = $_SERVER['HTTP_REFERER']; // where did the post submission come from?
// if there's a valid referrer, and it's not the default log-in screen
if ( !empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin') ) {
wp_redirect( $referrer . '?login=failed' ); // let's append some information (login=failed) to the URL for the theme to use

This second snippet shows you how to redirect your user to your login page you just have to change “home()” if it is not your login page.

//Redirect after logout
function ccw_redirect_logout_url(){

You just have to place both codes in your theme’s function.php. You must take note however, that using this WordPress Login and Logout quick fix assumes that you have your own login page.

That’s all there is to it. Enjoy!


Editorial Staff at ETN Multimedia is led by Alphonse Tan. Page maintained by Alphonse Tan

Back To Top