创建了一个短代码,但是当在一个页面上使用多个短代码时,传入的$att仅来自使用的最后一个短代码。我做错了什么?
public function init(){
add_action( \'wp_enqueue_scripts\',
array( $this, \'load_dialog_scripts\') );
add_action( \'wp_enqueue_scripts\',
array( $this, \'load_dialog_styles\') );
add_shortcode( \'post-dialog-button\',
array( $this ,\'post_dialog_func\') );
}
public function post_dialog_func( $atts ){
$a = shortcode_atts( array(
\'button_image\' => \'button image\',
\'post_id\' => \'some post id\',
\'image\' => \'post image here\',
\'header\' => \'post title here\',
\'content\' => \'post content here\',
\'post_footer\' => \'post footer info here\',
), $atts );
wp_localize_script( \'dialog-popup-script\', \'dialog_popup_script\', $a );
wp_enqueue_script( \'dialog-popup-script\' );
$shortcode_button = \'<div class="button-dialog-container">DEMO</div>\';
return $shortcode_button;
}
我在这里找到了同一问题的深入答案:
Localize variable for multiple Shortcodes