Skip to content

Instantly share code, notes, and snippets.

@chihirokaasan
Created February 19, 2016 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chihirokaasan/7262f01df02acc955af3 to your computer and use it in GitHub Desktop.
Save chihirokaasan/7262f01df02acc955af3 to your computer and use it in GitHub Desktop.
Add the jQuery only when the custom post type
function my_jquery($hook) {
if($hook == 'edit.php'){
global $post;
if ( $hook == 'post-new.php' || $hook == 'post.php' ) {
if ( 'custom_post_name' === $post->post_type ) {
wp_enqueue_script('custom_admin_script', get_bloginfo('template_url').'/js/my_jquery.js', array('jquery'));
}
}
}
}
add_action('admin_enqueue_scripts', 'my_jquery');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment