Limiting Available Blocks Within Gutenberg

Published: 26th November 2018

blog-limiting-blocks

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 design 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, $post) {

$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.


Previous Page

More Blog Entries

5 Custom Alerts You Need in Your Google Analytics Set-Up

Published: 15th May 2019

We’ve selected 5 custom alerts we think most businesses would benefit from having set up. If you’ve never used custom alerts before then be sure to read through our blog on setting them up here. W...

Read the full article

Adding Schema.org Structured Data

Published: 8th April 2019

It's fair to say that search engines have their work cut out, having to regularly crawl billions of websites, extract the information and then index this based on what they find. It's a pretty big tas...

Read the full article

Google Analytics for Beginners: Setting up Custom Alerts

Published: 26th March 2019

By using Custom Alerts you can keep an eye on your site usage and monitor specific changes without having to manually sift through the data in Google Analytics. What Are Custom Alerts and How Do They...

Read the full article

Get in touch today, let's talk about your next project

Follow us on Twitter

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

42 days ago

User Friendly Media
@UFMediaUK

There are so many different custom alerts combinations you can set in @googleanalytics! In our latest blog we loo… t.co

42 days ago

User Friendly Media
@UFMediaUK

In browser push notifications – are you missing out? Find our more: t.co #webdev #marketingt.co

43 days ago

User Friendly Media
@UFMediaUK

RT @Moz: Focusing on site speed will yield increasing benefits to #SEO, #UX, & customer loyalty that inevitably translates to revenue! Thi…

43 days ago

User Friendly Media
@UFMediaUK

Joomla Development Drupal Development Wordpress Development Shopify Setup and Customisation Google Analytics Google Ads Google Tag Manager Laravel Development Boot Strap Framework development Cloud Flare Content Distribution Google My Business WooCommerce Mailchimp
Any Questions? Ask away!