How to Restrict or Disable blocks in WordPress Block Editor?

0
How to Restrict or Disable blocks in WordPress Block Editor

As we all know that using blocks is very perceptive. Blocks are the way that the WordPress organizes content inside posts and pages. Blocks are invisible among the viewers. They are just a tool for you to work with posts or pages inside the WordPress Dashboard. It works in a transparent way so there isn’t much importance of it on a site. It appears in the background without any kind of interaction. Sometimes, users find it useless. In that case, it’s possible to restrict or disable blocks in the WordPress block editor. 

Restrict/Disable blocks in WordPress Block Editor

Let’s learn the easiest and quickest way to Disable this insignificant feature from our website. Here we have brought up to you the tutorial which will enable you to restrict/disable blocks by simply using a code. This is the most lightweight option. Be very careful while applying codes. Using manual code will be much easier. 

  • By doing this the users will be choosing the blocks that you want to enable. It’s much easier to include the blocks that you don’t will to enable in your WordPress Site. the code is mentioned below. Simply copy and paste it.  

function my_allowed_block_types( $allowed_block_types, $post ) {

return array(

‘core/paragraph’

);

}

add_filter( ‘allowed_block_types’, ‘my_allowed_block_types’);

  • By doing this you will be able to use paragraph block. All other blocks will be simply disabled. In order to enable more blocks, just add slugs in the array. 

function my_allowed_block_types( $allowed_block_types, $post ) {

return array(

‘core/paragraph’,

‘core/image’,

‘core/heading’,

‘ugb/button’

);

}

add_filter( ‘allowed_block_types’, ‘my_allowed_block_types’);

  • In order to find the block slug to include in the array. User Gutenberg Code Editor. 
Restrict or Disable blocks in WordPress Block Editor.
Restrict or Disable blocks in WordPress Block Editor.
  • In case of necessity, you can modify base code snippet to specific posts as per your choice using if rules. 

Wrapping Up:

In case, if you don’t like enabling the blocks to feature you can simply restrict or disable blocks. Coding manually is much easier than using plugins. It’s lengthy to use a plugin as you need to create a new account and do many more steps. Hope the information was useful. Meanwhile, if you have any question or suggestion, leave it in the comment section below. 

Also, Checkout, 

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.