我正试图在我的WordPress function.php中加入一个脚本,我似乎无法让它来获取脚本。
如果包含在标头中,则以这种格式工作。
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>,但是,当我在functions.php中包含它时,它不起作用
wp_enqueue_script('bootstrap-js', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js', array(), '3.3.6', true);有人能明白为什么当我排队的时候它不起作用吗?
全码
function theme_js()
{
wp_enqueue_script('jquery-js', 'https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array(), '3.1.1', true);
wp_enqueue_script('bootstrap-js', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js', array(), '3.3.6', true);
wp_enqueue_script('html5shiv-js', 'https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js', array('jquery'), '3.7.2', true);
wp_enqueue_script('respond-js', 'https://oss.maxcdn.com/respond/1.4.2/respond.min.js', array('jquery'), '1.4.2', true);
wp_enqueue_script('custom', get_template_directory_uri() . '/js/custom.js', array(), null, true);
}
add_action('wp_enqueue_scripts', 'theme_js');发布于 2017-03-02 15:15:02
您正在将其加载到页脚中,这可能不是您想要做的。最后的标志设置为true。
供参考
wp_enqueue_script( string $handle,string $src =‘,array $deps = array(),string bool重null $ver = false,bool $in_footer = false )
Try (现在包括您正在排队的jQuery的取消注册):
全码
if (!is_admin()) add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
function my_jquery_enqueue() {
wp_deregister_script('jquery');
wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js", false, null);
wp_enqueue_script('jquery');
}
function theme_js(){
// wp_enqueue_script('jquery-js', 'https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('jquery'), '3.1.1', true);
wp_enqueue_script('bootstrap-js', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js', array('jquery'), '3.3.6', true);
wp_enqueue_script('html5shiv-js', 'https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js', array('jquery'), '3.7.2', true);
wp_enqueue_script('respond-js', 'https://oss.maxcdn.com/respond/1.4.2/respond.min.js', array('jquery'), '1.4.2', true);
wp_enqueue_script('custom', get_template_directory_uri() . '/js/custom.js', array('jquery'), null, true);
}
add_action('wp_enqueue_scripts', 'theme_js');另外检查:引导程序的JavaScript需要jQuery版本1.9.1或更高,但低于bootstrap.min.js?ver=3.3.6:6的bootstrap.min.js?ver=3.3.6:6的版本3 ;)
https://stackoverflow.com/questions/42559078
复制相似问题