WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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'] ?

share|improve this question
    
For reference there is related trac discussion here core.trac.wordpress.org/ticket/19898 – Stephen Harris Aug 29 '14 at 15:38
up vote 32 down vote accepted

Use the global $pagenow;

if ( in_array( $GLOBALS['pagenow'], array( 'wp-login.php', 'wp-register.php' ) ) )
    run_my_funky_plugin();
share|improve this answer

$GLOBALS['pagenow'] doesn't work, use $_SERVER['PHP_SELF'].

if ( in_array( $_SERVER['PHP_SELF'], array( '/wp-login.php', '/wp-register.php' ) ) ){
    // do something.
}

and if your wordpress is not installed in the web root folder, you should use some params like YOUR_WP_PATH/wp-login.php to replace the elements in array.

share|improve this answer

More modern way to do that, it should work even when the wp-login URL is changed by plugins and when WP is in a subfolder, etc:

if(stripos($_SERVER["SCRIPT_NAME"], strrchr(wp_login_url(), '/')) !== false){
    /* ... */
}
share|improve this answer

I am only interested in register page, not in login page. So this might not be wanted by everybody.

$GLOBALS['pagenow'] returns index.php for me. Maybe because of buddypress or my theme.

So I used

is_page('register')

If you inspect the body of the registration page, it also has the ID as well, so if it says page-id-4906, you can use it this way if it works better:

is_page('4906')
share|improve this answer
    
This is only valid if a plugin is modifying the default login. – Michael Ecklund Mar 1 at 23:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.