How to Disable the Gutenberg Editor in WordPress

How to Disable the Gutenberg Editor in WordPress
546 Views
0
(0)

What is Gutenberg?

Gutenberg is a WordPress platform, block-based editor. Gutenberg published in November 2018, was introduced it. Since then, many website owners have abandoned the classic editor in favor of Gutenberg.

Why do you need to disable Gutenberg?

If you are not ready for the new WordPress 5 Gutenberg Editor, why not stick with the classic editor? If this seems familiar, then reading this page may assist you in Disabling WordPress Gutenberg Editor.

Follow these tips to disable the Gutenberg editor

1) : Disable Gutenberg Blocks in Code

You would have this after adding this code to your current theme’s functions.php file.

<?php
add_filter( 'allowed_block_types_all', 'cxc_allowed_block_types_call_back', 25, 2 );

function cxc_allowed_block_types_call_back( $allowed_blocks, $editor_context ) {

	return array(
		'core/image',
		'core/paragraph',
		'core/heading',
		'core/list',
		'core/list-item',
		'core/html'
	);

}
?>

2) : List of Gutenberg blocks editor

  • List of Gutenberg blocks 
Block Name Block Slug
Paragraphcore/paragraph
Tablecore/table
Listcore/list and core/list-item
Headingcore/heading
List of Gutenberg blocks 
  • Design Category
Block Name Block Slug
Columnscore/columns
Rowcore/row
Page Breakcore/nextpage
Spacercore/spacer
Buttonscore/buttons
Separatorcore/separator
Design category block slug table Gutenberg
  • Media category
Block Name Block Slug
Gallerycore/gallery
Media & Textcore/media-text
Imagecore/image
Videocore/video
Media category block slug table Gutenberg
  • Theme category
Block Name Block Slug
Site Titlecore/site-title
Post Titlecore/post-title
Post Contentcore/post-content
Login/Logoutcore/loginout
Post Datecore/post-date
Read Morecore/read-more
Post Featured Imagecore/post-featured-image
Theme category block slug table Gutenberg
  • Widgets category
Block Name Block Slug
Calendarcore/calendar
Latest Commentscore/latest-comments
Archivecore/archives
Page Listcore/page-list
Social Iconscore/social-links
RSScore/rss
Widget category block slug table Gutenberg

Allow or Disallow Specific Post Type Blocks

<?php
add_filter( 'allowed_block_types_all', 'cxc_allowed_block_types_to_post_call_back', 25, 2 );
 
function cxc_allowed_block_types_to_post_call_back( $allowed_blocks, $editor_context ) {

	$allowed_blocks = array(
		'core/image',
		'core/paragraph',
		'core/heading',
		'core/list',
		'core/list-item',
		'core/html'
	);
 
 	// Show In Post Pages.
	if( 'post' === $editor_context->post->post_type ) {
		$allowed_blocks[] = 'core/shortcode';
	}
 
	return $allowed_blocks;
 
}
?>

How to Blacklist Specific Blocks?

<?php
$registered_block_slugs = array_keys( WP_Block_Type_Registry::get_instance()->get_all_registered() );

echo '<pre>' . print_r( $registered_block_slugs, true ) . '</pre>';

/*
Array
(
    [0] => core/archives
    [1] => core/avatar
    [2] => core/block
    [3] => core/calendar
    [4] => core/categories
	 
	 ... and so on
*/
?>

Assume you don’t need the Archives and Calendar blocks.

<?php
add_filter( 'allowed_block_types_all', 'cxc_blacklist_blocks_call_back' );

function cxc_blacklist_blocks_call_back( $allowed_blocks ) {
	// get all the registered blocks
	$blocks = WP_Block_Type_Registry::get_instance()->get_all_registered();

	// then disable some of them
	unset( $blocks[ 'core/archives' ] );
	unset( $blocks[ 'core/calendar' ] );

	// return the new list of allowed blocks
	return array_keys( $blocks );
	
}
?>

How useful was this blog?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this blog.

Leave a comment

Your email address will not be published. Required fields are marked *