我正在创建一个自定义页面模板,其中包括this jQuery multi-selector 但无论我做什么,我似乎都无法让它发挥作用。
CSS和JS文件似乎都添加到了主题头文件中,但这是我粘贴选择器代码时一直看到的:
我的模板文件代码:
<select id=\'pre-selected-options\' multiple=\'multiple\'>
<option value=\'elem_1\' selected>elem 1</option>
<option value=\'elem_2\'>elem 2</option>
<option value=\'elem_3\'>elem 3</option>
<option value=\'elem_4\' selected>elem 4</option>
<option value=\'elem_100\'>elem 100</option>
</select>
我的职能。php文件:
function wptuts_scripts_load_cdn()
{
wp_register_script( \'multi-select\', \'https://www.mywebsite.com/selector/js/jquery.multi-select.js\', array(), null, false );
wp_register_script( \'bs4\', \'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha/js/bootstrap.min.js\', array(), null, false );
}
add_action( \'wp_enqueue_scripts\', \'wptuts_scripts_load_cdn\' );
function wptuts_styles_with_the_lot()
{
// Register the style like this for a theme:
wp_register_style( \'custom-style\', \'https://www.mywebsite.com/selector/css/multi-select.css\', array(), \'20120208\', \'all\' );
}
add_action( \'wp_enqueue_scripts\', \'wptuts_styles_with_the_lot\' );
我正在使用
Avada theme 如果这很重要的话。
这里可能有什么问题?
SO网友:Dave Romsey
这里是原始代码的调整版本。get_template_directory_uri()
使用,而不是对URL进行硬编码,脚本和样式是enqueud而不仅仅是注册的,并且指定了依赖项。
<?php
function wptuts_scripts_load_cdn() {
wp_enqueue_script( \'multi-select\', get_template_directory_uri() . \'/selector/js/jquery.multi-select.js\', array( \'jquery\' ), null, false );
// JavaScript for theme. Presumably where you\'d want to initialize the multi-select element.
//wp_enqueue_script( \'theme-scripts\', get_template_directory_uri() . \'/js/theme-scripts.js\', array( \'jquery\', \'multi-select\' ), null, false );
wp_enqueue_script( \'bs4\', \'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha/js/bootstrap.min.js\', array(), null, false );
}
add_action( \'wp_enqueue_scripts\', \'wptuts_scripts_load_cdn\' );
function wptuts_styles_with_the_lot() {
// Enqueue the style like this for a theme:
wp_enqueue_style( \'custom-style\', get_template_directory_uri() . \'/selector/css/multi-select.css\', array(), \'20120208\' );
}
add_action( \'wp_enqueue_scripts\', \'wptuts_styles_with_the_lot\' );