Skip to content

Instantly share code, notes, and snippets.

@MaryOJob
Last active April 20, 2020 11:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaryOJob/46754de838b03c4d4e6b6b983df5c021 to your computer and use it in GitHub Desktop.
Save MaryOJob/46754de838b03c4d4e6b6b983df5c021 to your computer and use it in GitHub Desktop.
Change the WordPress default Login to a Custom Login on your website
<?php
add_filter( 'login_url', 'marypmpro_custom_login_url', 10, 3 ); // marypmpro here is the name of my site
/**
* Filters the login URL.
*
* @since 2.8.0
* @since 4.2.0 The `$force_reauth` parameter was added.
*
* @param string $login_url The login URL. Not HTML-encoded.
* @param string $redirect The path to redirect to on login, if supplied.
* @param bool $force_reauth Whether to force reauthorization, even if a cookie is present.
*
* @return string
* As shown in example from https://developer.wordpress.org/reference/hooks/login_url/
*/
function marypmpro_custom_login_url( $login_url, $redirect, $force_reauth ){ // marypmpro here is the name of my site
// This will append /custom-login/ to you main site URL as configured in general settings (ie https://domain.com/custom-login/)
$login_url = site_url( '/custom-login/', 'login' );
if ( ! empty( $redirect ) ) {
$login_url = add_query_arg( 'redirect_to', urlencode( $redirect ), $login_url );
}
if ( $force_reauth ) {
$login_url = add_query_arg( 'reauth', '1', $login_url );
}
return $login_url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment