In WooCommerce, My Category Listing page and product listing page are rendered from archieve-product.php ( By Default) . How to check if page is_shop() in functions.php? As is_shop function does not work in functions.php. I simply want to remove my sidebar from Category listing page not from product listing page.
24 Answers
When placed inside a hook, is_shop will work in functions.php
add_action( 'template_redirect', 'custom_template_redirect' );
function custom_template_redirect() { if( is_shop() ) : // code logic here endif;
}Here is a list of all WooCommerce conditionals
1You can write a condition into "archive-product.php" for category page like,
$cate = get_queried_object(); if(is_product_category() && $cate->parent != 0 ){ // Write code here //include sidebar here }By using this code this will check the page for product_category and also check for a parent.
call it using WordPress Hook pre get posts
add_action('pre_get_posts','nameTheFunction');
function nameTheFunction(){ if(is_shop()){ // your code here }
}// function end hereRead more about pre get posts Hook
You can use function_exists
if( function_exists("is_shop") ) { // call it or do something else
}
else { // load it from somewhere
}Official docs:
5