Created
June 23, 2017 21:47
-
-
Save tripflex/ac477b59d20bd11c5856edcffc13e5ef to your computer and use it in GitHub Desktop.
Custom WordPress login url by filtering login_url
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'login_url', 'smyles_custom_login_url', 10, 3 ); | |
/** | |
* 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 | |
*/ | |
function smyles_custom_login_url( $login_url, $redirect, $force_reauth ){ | |
// 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