获取wordpress中已排队脚本的列表? [英] Get the list of enqueued scripts in wordpress?
问题描述
我想知道如何通过 wp_enqueue_script 获取在wordpress中排队的脚本列表.我已经做过一些研究,并检查了wp核心本身,但是我能得到的最接近的东西是:
I would like to know how to get the list of scripts enqueued in wordpress via wp_enqueue_script. I have done some research and checked the wp core itself but the closest I can get is something like:
add_options_page('Wp Sysinfo', 'Wp Sysinfo', 'manage_options', 'wp-sysinfo', 'sysinfo_page');
function sysinfo_page(){
global $wp_scripts;
print_r($wp_scripts->queue);
}
但是,它仅在管理页面中显示脚本,而不在前端显示.
However it only show scripts in the admin pages not the front end.
仅供参考:我正在构建一个插件来在wordpress中显示系统信息.这是为插件/主题作者提供有用的信息,以对用户报告的问题进行故障排除.
FYI: Im building a plugin to display system information in wordpress. This is to provide plugin/theme authors useful info to troubleshoot problems reported by users.
简而言之,我需要一种将所有脚本和样式都放入admin和前端的方法,并在自定义的admin页面中查看它们.
In short, I need a way to get all scripts and styles enqueued in both admin and frontend, and view them within a custom admin page.
推荐答案
有一个专用的Wordpress操作钩子,用于样式和脚本.这些钩子将在每个脚本或样式排入队列后触发:
There is a dedicated Wordpress action hook for styles as well as scripts. These hooks will be triggered after every script or style is enqueued:
function inspect_scripts() {
global $wp_scripts;
print_r($wp_scripts->queue);
}
add_action( 'wp_print_scripts', 'inspect_scripts' );
function inspect_styles() {
global $wp_styles;
print_r($wp_styles->queue);
}
add_action( 'wp_print_styles', 'inspect_styles' );
这篇关于获取wordpress中已排队脚本的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!