Can wp_localize_script be used within a shortcode?

Default parameters for wp_enqueue_script will output the script in the wp_head function. Shortcodes typically execute later, when main content is being output.

In that case, calling wp_localize_script in the Shortcode handler will have no effect, because the script has already been output.

Setting the $in_footer parameter to true when enqueueing the script will delay script output until wp_footer, so wp_localize_script will succeed in this case.