Skip to content

Instantly share code, notes, and snippets.

@carlodaniele
Created February 27, 2016 16:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save carlodaniele/b6c6e155c5fe97222546 to your computer and use it in GitHub Desktop.
Save carlodaniele/b6c6e155c5fe97222546 to your computer and use it in GitHub Desktop.
Switch the URL of default login page with the URL of a custom login page
<?php
/**
* Set a custom login page
*
* @param string $url Default login URL
* @param string $redirect Redirect URL on login
* @param bool $force_reauth Whether to force reauthorization
* @link https://developer.wordpress.org/reference/hooks/login_url/
*/
function frontend_login_url( $url, $redirect, $force_reauth ){
$new_login_url = home_url( '/login-form/' );
if ( !empty($redirect) ){
$new_login_url = add_query_arg( 'redirect_to', urlencode( $redirect ), $new_login_url );
}
if ( $force_reauth ){
$new_login_url = add_query_arg( 'reauth', '1', $new_login_url ) ;
}
return $new_login_url;
}
add_filter( 'login_url', 'frontend_login_url', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment