How can I conditionally load a JavaScript file only on WooCommerce product pages in WordPress?
I'm working on a WordPress website that uses WooCommerce, and I need to load a custom JavaScript file only on individual product pages. Currently, I'm using wp_enqueue_script() to load the file, but I want to make sure it doesn't load on the shop page, product categories, or other parts of the website. Here is what I'm trying: function custom_product_script() { if ( is_product() ) { wp_enqueue_script( 'custom-product-script', get_stylesheet_directory_uri() . '/js/product.js', array( 'jquery' ), '1.0.0', true ); } } add_action( 'wp_enqueue_scripts', 'custom_product_script' ); Is using is_produc
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.