Site logo

[Resolved] Disable a sidebar GB container when a certain page is viewed

Home Forums Support [Resolved] Disable a sidebar GB container when a certain page is viewed

Home Forums Support Disable a sidebar GB container when a certain page is viewed

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2464636
    George

    I want to disable a particular container that resides in a sidebar element when a certain page is viewed. Is that possible?

    #2464671
    Leo
    Staff
    Customer Support

    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;
    }
    #2464672
    George

    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.

    #2464675
    Leo
    Staff
    Customer Support

    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.

    #2464689
    George

    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!

    #2465414
    Leo
    Staff
    Customer Support

    Thanks for sharing the solution!

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