Created
May 22, 2018 23:52
-
-
Save kmwalsh/92d4d681c822a855ef2caa059ce3e117 to your computer and use it in GitHub Desktop.
Enqueuing WordPress scripts - all pages, just posts, just certain templates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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