我一直在尝试加载一个javascript文件,但是它没有加载,我查找了文档,但似乎找不出它为什么不排队。网站在这里:站点
在获得cookie错误消息的控制台im中,我还禁用了所有插件,最近将visual composer插件重新打开,但jquery似乎无法工作,尽管我可以很好地加载它。
我现在也像这样排队:
function edealsdirect_scripts() {
wp_register_script( 'jquery-cookie', get_template_directory_uri() . '/vendor/js/js.cookie.js', array( 'jquery', '', false ) );
wp_enqueue_script( 'jquery-cookie' );
}
add_action( 'wp_enqueue_scripts', 'edealsdirect_scripts' );发布于 2016-05-11 00:41:05
您正在注册一个脚本,然后将排队作为样式表。
试试这个(留下一个如何添加CSS的片段,这样您就可以在将来使用它,并看到它们之间的区别):
<?php
function mytheme_custom_scripts(){
// Register and Enqueue a Stylesheet
// wp_register_style( 'name-of-style', get_template_directory_uri() . '/css/custom-style.css');
wp_enqueue_style( 'name-of-style' );
// Register and Enqueue a Script
// get_stylesheet_directory_uri will look up child theme location
wp_register_script( 'jquery-cookie', get_stylesheet_directory_uri() . '/vendor/js/js.cookie.js', array('jquery'));
wp_enqueue_script( 'jquery-cookie' );
}
add_action('wp_enqueue_scripts', 'mytheme_custom_scripts');发布于 2016-05-11 00:19:14
您正在排队,而不是脚本。将wp_enqueue_style更改为wp_enqueue_script
而且,必须在jquery之后加载。函数调用中缺少$deps参数。请参阅文档
wp_register_script( 'jquery-cookie', get_template_directory_uri() . '/vendor/js/js.cookie.js', array( 'jquery' ) );
wp_enqueue_script( 'jquery-cookie' );发布于 2016-05-11 08:46:51
试试这个:
function edealsdirect_scripts() {
wp_enqueue_script( 'jquery-cookie', get_template_directory_uri() . '/vendor/js/js.cookie.js', array( 'jquery' ));
}
add_action( 'wp_enqueue_scripts', 'edealsdirect_scripts' );目前,在您的网站上,您没有加载脚本文件。我已经检查了这是否是cookie脚本的正确路径,它就是http://edeals.nickritson.co.uk/wp-content/themes/dragoncove-saltrock/vendor/js/js.cookie.js。
https://stackoverflow.com/questions/37150949
复制相似问题