2014-02-21 129 views
0

我想在WordPress網頁在我的側邊欄被稱爲即當我打電話邊欄樣包括WordPress的側邊欄的網頁

<?php get_sidebar(); ?> 

它會自動包含在該網頁上的JavaScript添加一個JavaScript的的JavaScript。有沒有這樣的鉤子,我可以附上我的JavaScript包括代碼?

回答

1

試試這個代碼,這將調用時任何側邊欄被稱爲: -

add_action('get_sidebar', 'add_before_siderbar'); 
function add_before_siderbar($name) 
{ 
    //Here `$name` is name of side bar, it will blank if default sidebar is call. 
    if($name == 'your-sidebar') 
    { 
     add_action('wp_enqueue_scripts', 'add_scripts'); 
    } 
} 
function add_scripts() 
{ 
    wp_enqueue_script('your-script', 'YOUR-SCRIPT-PATH', array('jquery'), 'version', false); 
} 
+0

非常感謝你 –