Wordpress - 如何检测当前页面是否为登录页面 [英] Wordpress - how detect if current page is the login page
问题描述
是否有比使用全局变量 $pagenow
来检测当前页面是否是登录页面更好的方法,例如 is_admin()
函数?
Is there a better way than using global variable $pagenow
to detect current page if it is login page, like a is_admin()
function?
if ($pagenow != 'wp-login.php' && !is_admin())
{
// Do something
}
有一个带有 getter get_current_screen()
的全局变量 $current_screen
(在 /wp-admin/includes/template.php 中声明
code>) 但它总是等于 null
.
There is a global variable $current_screen
with a getter get_current_screen()
(which is declared in /wp-admin/includes/template.php
) but it's always equal to null
.
在#15686(检测当前页面模板标签)上——WordPress Trac说 $pagenow
它通常被使用,但我认为不是将非动态页面与文件名而不是函数(如管理页面)进行比较的好方法.
On #15686 (Detect the current page template tag) – WordPress Trac it says $pagenow
it is usually used, but I think is not a good way to compare non-dynamic pages against the file's name instead of the function (like admin page).
推荐答案
虽然我倾向于同意其他人需要函数 is_login_page() 或类似的东西,但我在 https://wordpress.stackexchange.com/questions/12863/check-if-were-on-the-wp-login-page,我用来做以下:
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'));
}
这篇关于Wordpress - 如何检测当前页面是否为登录页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!