Use the is_login() function to check whether the current page is a login interface
New functions in WordPress 6.1 is_login()
, used to detect whether the current page is a login page. If it is, it will return true
, otherwise return false
。
This feature also takes into account custom login locations. by$_SERVER['SCRIPT_NAME']
Direct inspection rather thandid_action( 'login_form_login' )
or global check$pagenow
, this feature can work as early as possible, for example in must-use plug-ins.
In the following example, mount toinit
Hook, which only displays welcome messages on the login page. This check will consider pages with custom login screens in non-standard locations.
function add_text_to_login() {
if ( is_login() ) {
echo( "<h1>Welcome to the login screen!& lt;/h1>" );
}
}
add_action( 'init', 'add_text_to_login' );
For more information, see #19898.