[Resolved] No sidebar at mobile

Home Forums Support [Resolved] No sidebar at mobile

Home Forums Support No sidebar at mobile

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1652191
    roadlink

    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;
     } );
    #1652279
    Leo
    Staff
    Customer Support

    Hi there,

    Can you try replacing is_category() with is_product_category()?
    https://docs.woocommerce.com/document/conditional-tags/#section-5

    #1652532
    roadlink

    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;
     } );
    #1652570
    Elvin
    Staff
    Customer Support

    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;
    });

    A wise man once said:
    "Have you cleared your cache?"

    #1654122
    roadlink

    Perfect. Thanks

    #1655195
    Elvin
    Staff
    Customer Support

    Nice one. no problem. 😀

    A wise man once said:
    "Have you cleared your cache?"

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.