Created
November 10, 2022 15:46
-
-
Save omniacode/96096021d7d6cb6f73913016697b413c to your computer and use it in GitHub Desktop.
Conditionally Enqueue Scripts on Specific Page If It Is Not Already Enqueued
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
add_action( 'wp_enqueue_scripts', 'enqueue_my_custom_script' ); | |
function enqueue_my_custom_script() { | |
if ( 'page' === get_post_type() && is_page('ID') ) { | |
if ( wp_script_is( 'file.js', 'enqueued' ) ) { | |
return; | |
} else { | |
wp_register_script( 'file name', get_stylesheet_directory_uri() . '/js/file.js' ); | |
wp_enqueue_script( 'file name' ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment