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

Filters the login URL.


Description Description


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;
    }

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