Skip to content

Instantly share code, notes, and snippets.

@kmwalsh
Created May 22, 2018 23:52
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 kmwalsh/92d4d681c822a855ef2caa059ce3e117 to your computer and use it in GitHub Desktop.
Save kmwalsh/92d4d681c822a855ef2caa059ce3e117 to your computer and use it in GitHub Desktop.
Enqueuing WordPress scripts - all pages, just posts, just certain templates
function 8ii010b_scripts() {
// this adds your script to all pages on the site
wp_enqueue_script( 'custom-8ii010-js', get_template_directory_uri() . '/js/YOUR-JS-FILE.js', array(), '20151215', true );
// this adds your script to all single posts
if ( is_singular('post') ) {
wp_enqueue_script( 'custom-8ii010-js', get_template_directory_uri() . '/js/YOUR-JS-FILE.js', array(), '20151215', true );
}
// this adds your script only to a certain custom page template
if ( is_page_template('page-about.php') ) {
wp_enqueue_script( 'custom-8ii010-js', get_template_directory_uri() . '/js/YOUR-JS-FILE.js', array(), '20151215', true );
}
}
add_action( 'wp_enqueue_scripts', '8ii010b_scripts' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment