blog-limiting-blocks

Limiting Available Blocks Within Gutenberg

Published: 26th November 2018

Gutenberg is here and it's causing a stir within the Wordpress community. Ensure the new editor walks before it runs by limiting the default blocks and ensuring a smoother stress free transition.

We’re not against change, but after looking at the new editor we were concerned at just how much it allows site admins to do. With so many blocks to choose from and in a limitless combination clients could easily become confused when editing their content… worst still, they could get carried away! Adding too much content and breaking the bespoke design! Now you’ve got your design and marketing departments shouting at you; that well thought out UI is now broken and those calculated CTAs have been pushed below the page fold by 12 YouTube Videos, 4 headings (all H1s!) and 6 galleries.

OK, the above might be a slight exaggeration, but we’ve been in this game a long time and have seen this sort of thing happen! One solution is to limit the blocks available to your clients, this will allow you to roll Gutenberg out smoothly, training clients on the simpler easier to use blocks before giving them free reign on the whole lot. Let’s take a look at how to disable blocks with the simple code snippet below:

 

add_filter( 'allowed_block_types', 'theme_allowed_block_types' );

function theme_allowed_block_types($allowed_blocks) {

$blocks = array(
'core/image',
'core/paragraph',
'core/heading'

);

return $blocks;

}

 

Placing this code within your functions.php file will restrict the blocks available to those set within the array. You can see we’ve been very restrictive, only allowing 4 blocks. Currently the full list of default blocks is:

core/button
core/pullquote
core/table
core/preformatted
core/code
core/html
core/freeform
core/latest-posts
core/categories
core/cover-image
core/text-columns
core/verse
core/video
core/audio
core/block
core/paragraph

core-embed/twitter
core-embed/youtube
core-embed/facebook
core-embed/instagram
core-embed/wordpress
core-embed/soundcloud
core-embed/spotify
core-embed/flickr
core-embed/vimeo
core-embed/animoto
core-embed/cloudup
core-embed/collegehumor
core-embed/dailymotion
core-embed/funnyordie
core-embed/hulu
core-embed/imgur
core-embed/issuu
core-embed/kickstarter
core-embed/meetup-com
core-embed/mixcloud
core-embed/photobucket
core-embed/polldaddy
core-embed/reddit
core-embed/reverbnation
core-embed/screencast
core-embed/scribd
core-embed/slideshare
core-embed/smugmug
core-embed/speaker
core-embed/ted
core-embed/tumblr
core-embed/videopress
core-embed/wordpress-tv

As you can see there are fair few blocks available and if you’re developing bespoke themes having all of these available to a client could certainly cause issues, especially on larger enterprise projects where every detail is carefully considered by design and marketing departments. On such sites it might be that you limit blocks on pages, ensuring changes are subtle but within the news section you enable additional blocks, allowing for more creativity. This would require a simple adjustment to the above code:

 

add_filter( 'allowed_block_types', 'theme_allowed_block_types' );

function theme_allowed_block_types($allowed_blocks, $post) {

$blocks = array(
'core/image',
'core/paragraph',
'core/heading'

);

//If the post type is equal to post add more blocks to the array
if( get_post_type() == 'post' ) {
$blocks[] = 'core/shortcode';
$blocks[] = 'core/list';
}

return $blocks;

}

 

There are some really interesting blocks available with plenty more still to come. We’re looking forward to incorporating these into our future projects and with a limited approach and client training we’re optimistic they will bring value over the old editor.

More from our blog

Some text goes here, more SEO and stuff yeah, woop!

Contact us today

Ready to discuss your next project?

Pick a contact method below or use the form and a member of our team will get back to you as soon as possible.

Follow us

Can't get enough? Follow us on Twitter for all our latest developments.

Our new developer, Greg, hard at work here at the #UFMedia headquarters 🐶🖥️ #Sproodle #DogsofTwittter #DevonLifet.co

RT @Moz: #SEO Competitive Analysis 101: Step 1: Identify your top competitors Step 2: Perform keyword gap analysis Step 3: Perform link ga…

@allourwellbeing Oh my goodness!! Ahh all those beauties! Are they doodles of a sort?! 😍😍

RT @sejournal: Facebook Gives a Heads-Up About a New Tool That May Affect Ad Targeting via @MattGSouthern: t.co #SMM #S

@UFMediaUK