- This topic has 11 replies, 2 voices, and was last updated 4 years ago by
Tom.
-
AuthorPosts
-
May 9, 2019 at 5:35 am #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,
IvanMay 9, 2019 at 8:11 am #894259Tom
Lead DeveloperLead DeveloperHi 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 🙂
May 10, 2019 at 6:54 am #895331Ivan 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,
IvanMay 10, 2019 at 9:25 am #895517Tom
Lead DeveloperLead DeveloperI just adjusted the code above – can you give it another shot?
May 10, 2019 at 9:31 am #895525Ivan 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.
May 10, 2019 at 4:16 pm #895771Tom
Lead DeveloperLead DeveloperHmm, 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?
May 12, 2019 at 11:38 pm #897510Ivan 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
May 13, 2019 at 9:03 am #898074Tom
Lead DeveloperLead DeveloperSo it’s just the regular Categories widget?
May 14, 2019 at 2:01 am #898636Ivan Cazorla
I think so, yeah.
May 14, 2019 at 2:04 pm #899453Tom
Lead DeveloperLead DeveloperI’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
May 24, 2019 at 2:03 am #909461Ivan 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.
May 24, 2019 at 8:03 am #909781Tom
Lead DeveloperLead DeveloperSounds like a good workaround. Sorry I wasn’t able to help more!
-
AuthorPosts
- You must be logged in to reply to this topic.