WordPress if login page function, simple function and easy to use! two way to check if login page or not login page.
How To Check If Login Page?
Using global pagenow, we will checking wordpress if login page or not login page.
WordPress If Login Page Function
Two ways to check if login page.
The first way
Copy function code and paste it in your functions.php file.
function if_login_page() { return in_array( $GLOBALS['pagenow'], array('wp-login.php') ); }
Usage
if( if_login_page() ){ // now is login page, do something! }else{ // now is not login page, do something! }
Or:
if( !is_login_page() ){ // now is not login page, do something! } if( is_login_page() ){ // now is login page, do something! }
The second way
global $pagenow; if( 'wp-login.php' === $pagenow ){ // now is login page, do something! }
If you do not want login page, use:
global $pagenow; if( 'wp-login.php' !== $pagenow ){ // now is not login page, do something! }
Or:
global $pagenow; if( 'wp-login.php' === $pagenow ){ // now is login page, do something! }else{ // now is not login page, do something! }
Or:
global $pagenow; if( 'wp-login.php' !== $pagenow ){ // now is not login page, do something! }else{ // now is login page, do something! }