Skip to content

Instantly share code, notes, and snippets.

@tripflex
Created June 23, 2017 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tripflex/ac477b59d20bd11c5856edcffc13e5ef to your computer and use it in GitHub Desktop.
Save tripflex/ac477b59d20bd11c5856edcffc13e5ef to your computer and use it in GitHub Desktop.
Custom WordPress login url by filtering login_url
<?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