Last active
November 10, 2022 15:42
-
-
Save omniacode/5c80432ae27bd261fdecf5803c3439e8 to your computer and use it in GitHub Desktop.
Conditionally Enqueue JS per Post Type
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_cpt_script' ); | |
function enqueue_cpt_script() { | |
if ( 'cpt-type' === get_post_type() ) { | |
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