Hide / disable block elements in backend panel

Hi there,
I was wondering if there are any options to hide blocks completely in the bricks panel? I mean on the left when adding new blocks. As in all builder there are a lot of elements that I don’t use and probably won’t in the future or I want to hide them for the client because he should use the templates instead of the default blocks.

It’s okay to do this by code. For now I just hide them by CSS but that feels like a workaround. Maybe there is a better way.

/* Hide complete sections of blocks */
#bricks-panel-elements .category-general .bricks-add-element {
	display: none !important;
}

/* Hide a single blocks */
#bricks-panel-elements .bricks-add-element[data-element-name="icon"] {
	display: none !important;
}

I think that is this filter…

Cheers

Patric

2 Likes

As @Patric stated you can use the bricks/builder/elements hook. Could look like this:

add_filter( 'bricks/builder/elements', function( $elements ) {
    /* Currently available elements:
     * container, section, block, div, heading, text-basic, text, button, icon, image, video, divider, icon-box, social-icons, list, accordion, accordion-nested, tabs, tabs-nested, form, map, alert, animated-typing, countdown, counter, pricing-tables, progress-bar, pie-chart, team-members, testimonials, html, code, template, logo, facebook-page, image-gallery, audio, carousel, slider, slider-nested, svg, wordpress, posts, pagination, nav-menu, sidebar, search, shortcode, post-title, post-excerpt, post-meta, post-content, post-sharing, related-posts, post-author, post-comments, post-taxonomy, post-navigation
     */
    
    $not_needed = [
        'map',
        'alert',
        'countdown'
    ];
    
    return array_diff( $elements, $not_needed );
} );
4 Likes

That worked like a charm.
I’ve added the list into a ACF checkbox option field so I can now select the elements I need within wordpress.

Thank you for your help!

1 Like

Great idea! Cheers Patric

@diehingucker Is it possible to share how you created the acf fields to diable the elements from Wordpress? Thanks

@roberthaskin Sorry for the late reply.

The code you need is a short function. You may need to check for ACF so your website doesn’t crash when you disable ACF.

add_filter( 'bricks/builder/elements', function( $elements ) {
	$elements = get_field('bricks_fields', 'option');
	return $elements;
} );

Put this into your functions.php or a child theme or custom plugin whatever. The rest is done by ACF itself (note: ACF Pro + ACF Extended)

  1. Create options page.
  2. Create a field group applied to the option page.
  3. Add a field (select works best) to the field group called ‘bricks_fields’.
  4. Choices need to be a list of all existing fields (return value).
container
section
block
div
heading
text-basic
text
button
icon
image
video
divider
icon-box
social-icons
list
accordion
accordion-nested
tabs
tabs-nested
form
map
alert
animated-typing
countdown
counter
pricing-tables
progress-bar
pie-chart
team-members
testimonials
html
code
template
logo
facebook-page
image-gallery
audio
carousel
slider
slider-nested
svg
wordpress
posts
pagination
nav-menu
sidebar
search
shortcode
post-title
post-excerpt
post-meta
post-content
post-sharing
related-posts
post-author
post-comments
post-taxonomy
post-navigation

Note:

  1. All checked fields are visible, the rest is deactivated. Bricks may throw an error when you do this in an active instance.
  2. New Core Elements do not add without adding them to the select choices. (maybe there will be a core functions to get all available elements).

You see it’s not bulletproof but maybe you can work on it.

3 Likes