Skip to content

Instantly share code, notes, and snippets.

@raiden808
Last active April 22, 2018 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raiden808/ebdc1c7dfccac690f7e8ab66cf70d148 to your computer and use it in GitHub Desktop.
Save raiden808/ebdc1c7dfccac690f7e8ab66cf70d148 to your computer and use it in GitHub Desktop.
Enqueue script if it has shortcode
<?php
function enqueu_this_scipt(){
global $post;
if ( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'awesome_shortcode') ) {
wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', true );
}
}
add_action( 'wp_enqueue_scripts', 'enqueu_this_scipt' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment