1
在我的插件中,我需要包含1個CSS和2個js文件(jquery.min.js和jquery.googleplus-activity-1.0.min.js)。如何在Wordpress中包含jQuery插件?
我使用這個代碼
function my_init_method()
{
wp_deregister_script('jquery');
wp_enqueue_script('jquery', '' . get_bloginfo('wpurl') . '/wp-content/plugins/googe_plus/js/jquery.min.js');
}
function addHeaderCode() {
echo '<link type="text/css" rel="stylesheet" href="' . get_bloginfo('wpurl') . '/wp-content/plugins/googe_plus/css/style.css" />' . "\n";
}
function my_jsscripts_method() {
wp_deregister_script('jquery');
wp_register_script('jquery', '' . get_bloginfo('wpurl') . '/wp-content/plugins/googe_plus/js/jquery.googleplus-activity-1.0.min.js');
wp_enqueue_script('jquery');
}
add_action('init', 'my_init_method');
//Include CSS
add_action('wp_head', 'addHeaderCode');
//Include JS
add_action('wp_enqueue_scripts', 'my_jsscripts_method');
但不能js文件的添加兩者。 請記住,我必須包括jquery.min.js第一則CSS和其他js文件jquery.googleplus活動,1.0.min.js
不回答你的問題,但請注意,其他插件也可能使用jQuery。在添加JS之前檢查jQuery是否存在。 – Raptor 2012-01-09 09:01:11
@ShivanRaptor是的我知道,但我認爲全球可能使用不使用它,所以我必須包括它 – 2012-01-09 09:03:37