Archived topic
Disable a sidebar GB container when a certain page is viewed
5 replies · Started by George on December 16, 2022
I want to disable a particular container that resides in a sidebar element when a certain page is viewed. Is that possible?
Hey George,
It should be possible with CSS if that container has a custom class added.
Can you link me to the page in question if you need help with the CSS?
It should be something like:
.page-id-xxx .custom-class {
display: none;
}
Hi Leo, I can do the CSS, it's very easy, I just want to disable it completely, like gone from the markup. Maybe a GB filter and a conditional check if ( is page() ), or something.
I've not seen a solution for this unfortunately.
You could try checking with WP's support team - if Gutenberg editor has a way to make a block (any blocks) disappear, then I'd assume it would work with GB's container block.
Oops posted in the wrong thread.
You are right, it's the render_block filter. Here I remove a GB container when a custom term from a custom taxonomy is viewed.
add_filter( 'render_block', function( $content, $block ) {
if ($block['blockName'] === 'generateblocks/container') {
if (isset($block['attrs']['className']) ) {
if (strpos( $block['attrs']['className'], 'bet-of-the-day-sidebar' ) !== false && is_tax( 'my-taxonomy', 'my-term' ) ) {
return '';
}
}
}
return $content;
}, 10, 2 );
Thanks!
Thanks for sharing the solution!