I am using wordpress and I need to load a custom javascript only in a specific section of my webpage by callign its ID.
Is it possible ?
for now the js is loading in the whole page and there were conflicts with my theme
here is my code:
function my_custom_scripts() {
// wp_enqueue_script( 'jquery', 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js', array('jquery'), NULL, true );
wp_enqueue_script( 'gsap', 'https://cdnjs.cloudflare.com/ajax/libs/gsap/3.5.1/gsap.min.js', array('jquery'), NULL, true );
wp_enqueue_script( 'scrollTrigger', 'https://assets.codepen.io/16327/ScrollTrigger.min.js?v=32', array('jquery'), NULL, true );
wp_enqueue_script( 'smooth', 'https://cdnjs.cloudflare.com/ajax/libs/smooth-scrollbar/8.5.2/smooth-scrollbar.js', array('jquery'), NULL, true );
wp_enqueue_script( 'custom-js', get_stylesheet_directory_uri() . '/custom.js', array( 'jquery' ),'',true );
}
add_action( 'wp_enqueue_scripts', 'my_custom_scripts' );```