Created
July 17, 2018 17:07
-
-
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
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
<?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