2014-02-21 134 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

非常感谢你 –