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

Adding Schema.org Structured Data

Published: 8th April 2019

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

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

Add a Custom Colour Pallet to Gutenberg

Published: 28th November 2018

We've already discussed how the new editor comes with blocks and how to limit these in our article Limiting Blocks Within Gutenberg. In this article we want to look at controlling which, if any, colou...

Read the full article

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

Follow us on Twitter

Adding #structureddata to your website ensures search engines are getting the right information, your content is ge… t.co

12 days ago

User Friendly Media
@UFMediaUK

Google Analytics for beginners - how to set up custom alerts? Let us show you how! --> t.co t.co

26 days ago

User Friendly Media
@UFMediaUK

@HackSpaceMag Nice!

39 days ago

User Friendly Media
@UFMediaUK

RT @googlewmc: In the second episode of the JavaScript SEO series, @g33konaut covers: 🤔 What is a JS site? 🕵️‍♀️ When to pay attention to…

45 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