I don’t know if it is the ‘best’ place, but get_header
is early enough to still enqueue scripts:
function at_set_header () {
global $post, $has_the shortcode;
if ( is_object( $post ) && has_shortcode( $post->post_content, 'shortcode_name') ) {
$has_the_shortcode = true;
wp_enqueue_script( 'my-ajax-handle', FAU_PLUGIN_URL . 'js/ajax.js', array( 'jquery' ) );
wp_localize_script( 'my-ajax-handle', 'the_ajax_script', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
}
}
add_action( 'get_header', 'at_set_header');
The $has_the_shortcode
global might be usefull to decide about other resources at later stages.