Created a shortcode, however when multiple shortcodes are used on a page the $atts passed in are only from the last shortcode that was used. What am I doing wrong?

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;

I was able to find an in depth answer to this same problem here: Localize variable for multiple Shortcodes

1 Answer 1


Each time you're using wp_localize_script you're replacing the values inside the dialog_popup_script object. If each popup requires different settings, and those settings are set on the shortcode, you might be better off storing the values as data attributes on the div.

  • Ah I understand now! This led me to find an in depth look at a solution. Jul 23, 2017 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.