How can I check if the current page is wp-login.php
or wp-signup.php
?
Are there more elegant solutions than using $_SERVER['REQUEST_URI']
?
1
Use the global $pagenow
, which is a common global set by WordPress at runtime:
if ( $GLOBALS['pagenow'] === 'wp-login.php' ) {
// We're on the login page!
}
You can also check the type of login page, for example registration:
if ( $GLOBALS['pagenow'] === 'wp-login.php' && ! empty( $_REQUEST['action'] ) && $_REQUEST['action'] === 'register' ) {
// We're registering
}
Following code is considered legacy and should not be used (wp-register.php
was deprecated & subsequently removed quite a while back):
if ( in_array( $GLOBALS['pagenow'], array( 'wp-login.php', 'wp-register.php' ) ) )
run_my_funky_plugin();