[Resolved] Not show the sidebar when there's no widgets

Home Forums Support [Resolved] Not show the sidebar when there's no widgets

Home Forums Support Not show the sidebar when there's no widgets

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #893964
    Ivan Cazorla

    Hi there,

    Right now I’ve set a widget on my sidebar to show the sub categories, as you can see here (https://www.deacampada.com/categ/descanso/)

    But when there’s no more subcategories to show I would like to hide the entire sidebar, because there’s a huge useless white column at the left, as you can see here (https://www.deacampada.com/categ/descanso/colchones/colchones-individuales/)

    Is there a way to deactivate the sidebar when there’s no widgets on it?

    Let me know.

    Thanks,
    Ivan

    #894259
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Try this filter:

    add_filter( 'generate_sidebar_layout', function( $layout ) {
        if ( 'left-sidebar' === $layout && ! is_active_sidebar( 'sidebar-2' ) ) {
            return 'no-sidebar';
        }
    
        return $layout;
    } );

    Adding PHP: https://docs.generatepress.com/article/adding-php/

    Let me know 🙂

    #895331
    Ivan Cazorla

    Hi Tom,

    Thank you but it doesn’t work as I wanted, even when there should be a widget it has disabled the entire sidebar.

    If I deactivate the php code you gave me, I can see my widget again.

    I only need to deactiate the sidebar when the widget I have inside of it doesn’t have any information to show (blank).

    Let me know,
    Ivan

    #895517
    Tom
    Lead Developer
    Lead Developer

    I just adjusted the code above – can you give it another shot?

    #895525
    Ivan Cazorla

    Now I can see the sidebar but when there’s no widget to show there’s still the white column on the left as you can see here (https://www.deacampada.com/categ/mobiliario-camping/sillas-camping/sillas-altas/)

    Let me know.

    #895771
    Tom
    Lead Developer
    Lead Developer

    Hmm, something must be altering the core output of the widget. What determines whether something appears in that widget or not? Is it a core widget you’re using, or a plugin?

    #897510
    Ivan Cazorla

    Hi, if there are more subcategories to show it will show them, if not the widget won’t show. Actually I think is a widget I can choose from the widgets search, not sure now if it appears by a plugin or not.

    let me know

    #898074
    Tom
    Lead Developer
    Lead Developer

    So it’s just the regular Categories widget?

    #898636
    Ivan Cazorla

    I think so, yeah.

    #899453
    Tom
    Lead Developer
    Lead Developer

    I’m not sure if we can determine if the categories widget is empty. Maybe you can force the widget to show the categories no matter what?: https://wordpress.stackexchange.com/a/25002/90661

    #909461
    Ivan Cazorla

    I’ve tried that but it didn’t worked for me. I’ve added another widget/filter so that when the sidebar would be empty, now it has some other widgets to show.

    #909781
    Tom
    Lead Developer
    Lead Developer

    Sounds like a good workaround. Sorry I wasn’t able to help more!

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