php - Wordpress 如何使用 get_current_screen 和全局 pagenow
问题描述
我不明白以下两者之间的区别
获取当前屏幕
主页
你能帮我解决这个问题吗?
解决方案
它将“在未定义屏幕时返回当前屏幕对象或 null”。
如果你想用它来检测admin pages
,那么使用不同的钩子,例如你可以使用current_screen
钩子:
add_action('current_screen', 'detecting_current_screen');
function detecting_current_screen()
{
$current_screen = get_current_screen();
print_r($current_screen);
}
或者
add_action('current_screen', 'detecting_current_screen');
function detecting_current_screen()
{
global $current_screen;
print_r($current_screen);
}
如果你想在client-side
返回 null 的 and 上使用它,那么你可以使用一个名为 的全局变量$pagenow
。
注意: $pagenow
会给你模板名称。
global $pagenow;
echo $pagenow;
或者
echo $GLOBALS["pagenow"];
这应该为您提供您所在模板的名称:
add_action( 'wp_footer', function () {
global $pagenow;
echo $pagenow;
}, 999 );
如果上面提到的方法都不适合您,那么您可以使用另一个名为$post
.
或者
您可以使用以下方法检查您的页面:
推荐阅读
- java - 无法在 Android Studio 中配对蓝牙设备
- hdfs - 使用java上传hdfs文件
- amazon-web-services - 如何使用单个代码管道部署多个 Lambda 函数
- java - 能被 4 整除的对
- python - 在 Python 中查找大约一分钟前的最近数据
- python-3.x - 如何从使用 BeautifulSoup 中提取表值
- laravel - 从 Laravel API 访问图像文件到 Vue Cli 3
- c++ - 如何使用 string(int, char) 函数为声明的字符串添加或更改值?
- c# - 无法加载文件或程序集“NewtonSoft.Json,版本=12.0.0.0”
- postgresql - Notebook 中的 psycopg2 如何连接到 psql 终端?