Best Practices for Seperating jQuery from HTML/PHP

You can target a specific page using is_page() when you are enqueueing your JS file.

function my_scripts_method() {
    if( is_page('your page title') ){
      wp_enqueue_script( 'your-js-script' );
    }
}

add_action( 'wp_enqueue_scripts', 'my_scripts_method' ); 

This way, you will conditionally enqueue your JS to that page only.

Leave a Comment