Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Shortcode style enqueue #4
<?php
function custom_shortcode_scripts() {
global $post;
if( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'myshortcode') ) {
wp_enqueue_script( 'my-script');
}
}
add_action( 'wp_enqueue_scripts', 'custom_shortcode_scripts');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment