2014-01-28 258 views
0

你能幫我嗎?我寫的jquery accordion的javascript代碼放在哪裏?我應該把它放在file.js中,並且在functions.php中調用函數, wp_register,wp_enqueue,add_item?我是這個系統中的新手。非常感謝您的幫助Jquery在wordpress中的手風琴菜單

回答

0

要添加自定義JavaScript到您的網站,你應該看看wp_enqueue_script函數。

您可以在您的主題的functions.php或您創建的插件文件中使用它,具體取決於您是否希望它成爲主題的一部分。

下面的例子是從上面鏈接的頁面並且還覆蓋用於排隊CSS的等效功能:

/** 
* Proper way to enqueue scripts and styles 
*/ 
function theme_name_scripts() { 
    wp_enqueue_style('style-name', get_stylesheet_uri()); 
    wp_enqueue_script('script-name', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', true); 
} 

add_action('wp_enqueue_scripts', 'theme_name_scripts');