Exclude Blocks from the Block Based Widgets Editor

Support MB Blocks Exclude Blocks from the Block Based Widgets EditorResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #43580
    gerdagerda
    Participant

    Hey there!
    MB Blocks seem to not work properly in the Block Based Widgets Editor. Is there a way to exclude them from the Block Based Widgets Editor and show them in the Page/Post Block Editor only?
    Thanks!

    #43589
    PeterPeter
    Moderator

    Hello there,

    You can use PHP code to register the block, then check if the current page is the widget page and return $meta_boxes variable at that point. For example:

    // Register a hero content block for Gutenberg.
    add_filter( 'rwmb_meta_boxes', function( $meta_boxes ) {
        global $pagenow;
        if ( $pagenow == 'widgets.php' ) {
            return $meta_boxes;
        }
    
        $meta_boxes[] = [
            'title' => 'Hero Area',
            'id'    => 'hero-area',
            'type'  => 'block', // Important.
            ...
        ];
        return $meta_boxes;
    } );

    Follow the WordPress documentation https://codex.wordpress.org/Global_Variables#Admin_Globals

    #43593
    gerdagerda
    Participant

    Awesome, that works, thank you!

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