apply_filters( 'login_url', string $login_url, string $redirect, bool $force_reauth )

Filters the login URL.


Parameters Parameters

$login_url

(string) The login URL. Not HTML-encoded.

$redirect

(string) The path to redirect to on login, if supplied.

$force_reauth

(bool) Whether to force reauthorization, even if a cookie is present.


Top ↑

Source Source

File: wp-includes/general-template.php

View on Trac



Top ↑

Changelog Changelog

Changelog
Version Description
4.2.0 The $force_reauth parameter was added.
2.8.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by tripflex

    Here’s an example of filtering the `login_url` to specify a custom one:

    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;
    }
  2. Skip to note 2 content
    Contributed by johnzoet1

    Tested this login_url filter and it works fine for login links on the website, for example on blog pages.
    The filter will not work for a browser URL like /wp-login.php.

    This can be useful in case you have a custom login form for subscribers, while administrators still login with the WordPress core login form when two-factor authentication is enabled.

    A custom login form like those of User Registration plugin will not work with 2FA. This is where the core login form is still useful.

You must log in before being able to contribute a note or feedback.