Archived topic
No sidebar at mobile
5 replies · Started by roadlink on February 9, 2021
Hello,
I am trying to remove sidebar from woocommerce categories if visitor use mobile phones.
I don't want to use CSS thus I copied this code from here and here.
I clean the cache and tried to reach from mobile. I still see the sidebar at the bottom of content.
What can I do?
add_filter( 'generate_sidebar_layout', function( $layout ) {
// If we are on a category + mobile set the sidebar
if ( is_category() && wp_is_mobile() ) {
return 'no-sidebar';
}
// Or else, set the regular layout
return $layout;
} );
Hi there,
Can you try replacing is_category() with is_product_category()?
https://docs.woocommerce.com/document/conditional-tags/#section-5
Hi Leo,
Thanks, worked perfect.
How to add 3rd rule, which is if search?
I tried below code but didn't work.
Or I should add 2 filter seperately?
add_filter( 'generate_sidebar_layout', function( $layout ) {
// If we are on a category + mobile set the sidebar
if ( is_product_category() && wp_is_mobile() && is_search() ){
return 'no-sidebar';
}
// Or else, set the regular layout
return $layout;
} );
Hi there,
Try this:
add_filter( 'generate_sidebar_layout', function( $layout ) {
// If we are on a category + mobile set the sidebar
if ( is_search() || is_product_category() && wp_is_mobile() ){
return 'no-sidebar';
}
// Or else, set the regular layout
return $layout;
});
Perfect. Thanks
Nice one. no problem. :D