Skip to content

Instantly share code, notes, and snippets.

@Edwardtonnn
Created July 17, 2018 17:07
Show Gist options
  • Save Edwardtonnn/427463c43fcf659245eef0ae403a49fe to your computer and use it in GitHub Desktop.
Save Edwardtonnn/427463c43fcf659245eef0ae403a49fe to your computer and use it in GitHub Desktop.
Conditionally Enqueue JS file to certain pages of WP site. Specifically, NOT enqueue certain pages on WP site
<?php
//Function to add custom.js functionality to header only if the page is NOT contact page
add_action( 'wp_enqueue_scripts', 'conditional_header');
function conditional_header(){
if(is_page('contact') == false){
wp_enqueue_script(
'custom',
get_stylesheet_directory_uri() . '/js/custom.js',
array('jquery'),
null,
true
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment