Skip to content

Instantly share code, notes, and snippets.

@georgejipa
Created July 25, 2017 08:26
Show Gist options
  • Save georgejipa/e624387af38a9e89917663467383c90e to your computer and use it in GitHub Desktop.
Save georgejipa/e624387af38a9e89917663467383c90e to your computer and use it in GitHub Desktop.
shortcode embed static assets
function enqueue_assets() {
if (!is_singular()) {
return;
}
$content = get_post_field('post_content', get_the_ID());
if (!has_shortcode($content, 'shortcode_name_here')) {
return;
}
wp_enqueue_script('contact_js', get_template_directory_uri() . '/assets/js/contact.js', array(), '1.1', true);
}
add_action('wp_enqueue_scripts', 'enqueue_assets');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment