我尝试使用is_page()将URL传递给,但是我试图在脚本上排队的页面是"races/community/add“,而不是像”约-us“那样的一个片段。用is_page()可以做到这一点吗?或者我应该以另一种方式来处理这个问题吗?
add_action( 'wp_enqueue_scripts', 'enqueue_date_picker_styles_and_scripts', 101);
function enqueue_date_picker_styles_and_scripts() {
if ( is_page('races/community/add') ) {
wp_enqueue_style('bootstrap-datepicker-css', '//cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/css/bootstrap-datepicker.standalone.css');
wp_enqueue_script('bootstrap-datepicker-js', '//cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/js/bootstrap-datepicker.min.js', array('jquery'),'1.8.0', true);
}
}发布于 2019-04-27 13:47:45
是只接受一个可选参数$page,该参数应该是(int|string|array),表示Page ID、title、slug或此类数组。
在标准WP安装上,您的代码应该如下所示。
add_action( 'wp_enqueue_scripts', 'enqueue_date_picker_styles_and_scripts', 101);
function enqueue_date_picker_styles_and_scripts() {
if ( is_page('page-slug-here') ) { // Replace page-slug-here with slug of page at races/community/add
wp_enqueue_style('bootstrap-datepicker-css', '//cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/css/bootstrap-datepicker.standalone.css');
wp_enqueue_script('bootstrap-datepicker-js', '//cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/js/bootstrap-datepicker.min.js', array('jquery'),'1.8.0', true);
}
}https://wordpress.stackexchange.com/questions/336469
复制相似问题