我׳正在尝试创建一个手风琴短代码。当我用wp_enqueue_script函数加载脚本时,它只能用于jquery库,而不是定制脚本。
jQuery(document).ready(
function() {
$('#ks-accordion').accordion();
}
);以下是完整的代码:
// Container
function ks_accordion($atts, $content = null) {
extract( shortcode_atts( array(
'id' => ''
), $atts ) );
wp_enqueue_script('jquery-ui-accordion');
wp_enqueue_script('shortcode', get_template_directory_uri().'/functions/shortcodes/js/shortcodes.js');
return '<div id="accordion">'.do_shortcode($content).'</div>';
}
add_shortcode( 'accordion', 'ks_accordion' );
// Section
function ks_accordion_section($atts, $content = null) {
extract( shortcode_atts( array(
'title' => 'My Title',
), $atts ) );
return '<h6><a href="#">'.$title.'</a></h6><div><p>'.do_shortcode($content).'</p></div>';
}
add_shortcode( 'accordion_section', 'ks_accordion_section' );这是我在前端得到的代码:
<div id="ks-accordion"><br>
<h6><a href="#">Title</a></h6><div><p>Content</p></div><br>
<h6><a href="#">Title1</a></h6><div><p>Content</p></div><br>
<h6><a href="#">Title2</a></h6><div><p>Content</p></div><br>
</div>我也不明白为什么它会创建这些<br>
谢谢
发布于 2013-10-28 13:29:39
wp_enqueue_script('shortcode', get_template_directory_uri().'/functions/shortcodes/js/shortcodes.js', array('jquery'));希望这能有所帮助!
https://stackoverflow.com/questions/19635654
复制相似问题