Reputation: 167
I want to enqueue js and css for product category, shop and single product pages only. The below works but I wonder if there is a better way to do it?
function my_enqueue_stuff() {
if(is_shop() or is_product() or is_product_category())
{
wp_enqueue_script( 'style-css', get_stylesheet_directory_uri() . '/assets/css/style.css');
}
}
add_action( 'wp_enqueue_scripts', 'my_enqueue_stuff' );
On the same token, what is the correct way to use !? Below doesn't work.
function not_needed(){
if(!is_shop() or !is_product() or !is_product_category()){
return;
}
Upvotes: 1
Views: 1652
Reputation: 11282
Try the below code.
function my_enqueue_stuff() {
if( is_shop() || is_product() || is_product_category() ) {
wp_enqueue_script( 'style-css', get_stylesheet_directory_uri() . '/assets/css/style.css');
}
}
add_action( 'wp_enqueue_scripts', 'my_enqueue_stuff' );
UPDATE as per OP Request
function my_enqueue_stuff() {
if( !is_shop() && !is_product() && !is_product_category() ) {
wp_enqueue_script( 'style-css', get_stylesheet_directory_uri() . '/assets/css/style.css');
}
}
add_action( 'wp_enqueue_scripts', 'my_enqueue_stuff' );
Upvotes: 1