wordpress 在特定页面上排队管理脚本 [英] wordpress enqueue admin scripts on specific page
问题描述
我写了一个插件,在管理端需要一些 js 和 css 文件.
I wrote a plugin that requires some js and css file on the admin side.
我这样排队:
function checkin_page_files() {
if ( is_page('/admin.php?page=reports_Systems')) {
wp_enqueue_style( 'checkin-page-style', content_url() . '/plugins/reports/includes/checkin_page/style.css' );
wp_enqueue_script( 'checkin-page-js', content_url() . '/plugins/reports/assets/js/checkinPageJavascripts.js', array(), false, false );
wp_enqueue_script( 'checkin-live-validation-js', content_url() . '/plugins/reports/assets/js/liveValidation.js', array(), false, false );
}
}
add_action( 'admin_enqueue_scripts', 'checkin_page_files', 0 );
而且,如您所见,我试图指定仅当页面为 /admin.php?page=reports_Systems
时才包含它们,但这似乎不是工作.
and, as you can see, I am trying to specify that I'd like to include them only if the page is /admin.php?page=reports_Systems
, but that doesn't seem to work.
没有 if 语句,文件被正确包含,所以这不是路径错误.
Without the if statement, the files are included properly, so it's not a path error.
我怎样才能做到这一点?我在网上看到的所有示例都使用 if 语句来提供类似 admin.php
或 post.php
的页面,但没有 ?
.
How can I achieve this?
All the examples I saw online used the if statement to provide a page like admin.php
, or post.php
, without the ?
.
我认为我的不工作的原因是因为 ?
而我找不到这样的例子.
I think that the reason why mine doesn't work is because of the ?
and I wasn't able to find examples like this.
提前致谢
推荐答案
在这里您可以检查 $_GET 变量 'page'.Wordpress 有一个内置方法 get_query_var() 可以从 url 中获取 $_GET 变量.
Here you can check for the $_GET variable 'page'. Wordpress has a built in method get_query_var() to get the $_GET variable from the url.
if(get_query_var('page') == reports_Systems){
//enqueue your scripts
}
这篇关于wordpress 在特定页面上排队管理脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!