Wordpress 向主题添加javascript
我正在尝试将Nivo滑块代码(而不是WP插件)添加到主题中。我通过将以下内容添加到functions.php中完成了此操作:Wordpress 向主题添加javascript,wordpress,wordpress-theming,Wordpress,Wordpress Theming,我正在尝试将Nivo滑块代码(而不是WP插件)添加到主题中。我通过将以下内容添加到functions.php中完成了此操作: /* Add scripts for theme to work*/ function theme_add_scripts() { wp_enqueue_script('jquery'); //omit if jQuery already included wp_enqueue_script('nivoslider', bloginfo('stylesheet_
/* Add scripts for theme to work*/
function theme_add_scripts() {
wp_enqueue_script('jquery'); //omit if jQuery already included
wp_enqueue_script('nivoslider', bloginfo('stylesheet_url') . '/wp-content/themes/pingst/nivo-slider/jquery.nivo.slider.pack.js', 'jquery', '2.7.1');
}
add_action('init', 'theme_add_scripts');
看起来应该行得通,但有两个问题
wp_enqueue_script('nivoslider', bloginfo('stylesheet_url') . '/wp-content/themes/pingst/nivo-slider/jquery.nivo.slider.pack.js', 'jquery', '2.7.1');
应该是
wp_enqueue_script('nivoslider', get_bloginfo('stylesheet_directory') . '/nivo-slider/jquery.nivo.slider.pack.js', 'jquery', '2.7.1');
这应该可以解决问题nr2,也可以解决问题nr1主题中header.php的前2-3行是什么?当前,您的站点在doctype之前输出style.css文件。解决这个问题可能是第一个问题。
wp_enqueue_script('nivoslider', bloginfo('stylesheet_url') . '/wp-content/themes/pingst/nivo-slider/jquery.nivo.slider.pack.js', 'jquery', '2.7.1');
wp_enqueue_script('nivoslider', get_bloginfo('stylesheet_directory') . '/nivo-slider/jquery.nivo.slider.pack.js', 'jquery', '2.7.1');