wp_localize_script not passing the data

As it stands, your shortcode will be executed after wp_enqueue_scripts — when the post content is output. That’s why the data isn’t available to your scripts during wp_enqueue_scripts for wp_localize_script.

wp_enqueue_script( string $handle, string $src = false, array $deps = array(), string|bool|null $ver = false, bool $in_footer = false )

You would;

A) Need to gather your shortcode attributes ahead of time.

B) Put your custom script in the footer and output <script> data during the shortcode’s output.

C) Put your custom script in the footer and output inline js during wp_print_footer_scripts. You may need to wrap your custom scripts in closures to execute after localize has been added.

D) Locallize during the shortcode


Here is an example of localizing during the shortcode:

function some_shortcode( $atts )
{
    $data = shortcode_atts(
        array (
            'arrows' => TRUE
        ),
        $atts
    );

    wp_enqueue_script( 'your_script_name' );

    wp_localize_script(
        'your_script_name',
        'yourScriptObject',
        $data
    );

    return 'a string of whatever';
}