Wordpress - how detect if current page is the login page

后端 未结 4 1523
生来不讨喜
生来不讨喜 2021-02-05 06:39

There is a better way than using global variable $pagenow to detect current page if is login page, like a is_admin() ?

if ($pagenow !=          


        
相关标签:
4条回答
  • 2021-02-05 06:53

    While I tend to agree with others on the need for a function is_login_page() or something similar, I found what seems to be the best answer at https://wordpress.stackexchange.com/questions/12863/check-if-were-on-the-wp-login-page, which I used to make the following:

    <?php
    function is_login_page() {
        return in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'));
    }
    
    0 讨论(0)
  • 2021-02-05 06:56

    Incase you want to be as non WP independant as possible; for instance in a plugin keeping future changes out of scope. You can use something like this:

    function is_login_page() {
        return !strncmp($_SERVER['REQUEST_URI'], '/wp-login.php', strlen('/wp-login.php'));
    }
    
    0 讨论(0)
  • 2021-02-05 07:00

    Can't you explain what are you going to do with it? So I can tell if you should code using wordpress hooks.

    or you can use the absolute uri, just match it with wp-login.php

    <?php
    $uri = $_SERVER['REQUEST_URI'];
    
    echo $uri;
    

    ?>

    0 讨论(0)
  • 2021-02-05 07:08

    If you are like me, and you actually tried to de-register / mess with the jQuery that WordPress automatically loads, then the correct answer is:

    Don't use wp_print_styles to register your scripts – use wp_enqueue_scripts instead!

    This hook will run only on the frontend, not on the login page, so there's no need for workarounds.

    Nacin is explaining it here: http://make.wordpress.org/core/2011/12/12/use-wp_enqueue_scripts-not-wp_print_styles-to-enqueue-scripts-and-styles-for-the-frontend/

    0 讨论(0)
提交回复
热议问题