Step 1: Register Script
Register your JavaScript file in word-press
?phpfunction wpb_adding_scripts() {wp_register_script('my_amazing_script', plugins_url('amazing_script.js', __FILE__), array('jquery'),'1.1', true);wp_enqueue_script('my_amazing_script');} add_action( 'wp_enqueue_scripts', 'wpb_adding_scripts' ); ?>Step 2:
Inside your theme’s functions.php add something like this:
function my_conditional_enqueue_script() {
global $post;
if (is_single($post->ID) && in_category('mouse', $post->ID)) {
wp_enqueue_script('mousescript');
}
}
add_action('wp_enqueue_scripts', 'my_conditional_enqueue_script');
Also, make sure you use wp_register_script before you attempt to enqueue.
Resources:
Register-http://www.wpbeginner.com/wp-tutorials/how-to-properly-add-javascripts-and-styles-in-wordpress/
Enqueue-https://wordpress.stackexchange.com/questions/83849/how-to-enqueue-script-based-on-post-category