Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.