Many older WordPress users are not ready to make the jump to Gutenberg and prefer the Classic editor, or they return to using WordPress only to find a litany of changes and immediately want things back to the old way.
Others want consistency between post types finding that sometimes some custom post types only have the classic editor (either purposefully done or improperly and ignorantly done).
Finally, others don’t have a need for such a powerful editor and just want simple ability to add content like a Word processor not liking how the Gutenberg editor makes every paragraph its own block.
Regardless of the reason or rationale, it is quite simple to pre-populate a “post” (regardless of post type) with the classic editor. So you don’t need to add the Classic editor plugin any longer!
To support the default classic Gutenberg block for just one post type, simply add the following code snippet to your functions.php
file:
<?php
add_filter( 'allowed_block_types', 'wps_enable_gutenberg_classic_block_for_one_post_type', 10, 2 );
/**
* Adds a default Classic block if no default content exists for one post type.
*
* @param bool|array $allowed_block_types Array of block type slugs, or
* boolean to enable/disable all.
* @param \WP_Post $post The post resource data.
*
* @return bool|array
*/
function wps_enable_gutenberg_classic_block_for_one_post_type( $allowed_block_types, $post ) {
// If not our post type, bail.
// Change my_post_type to post to enable only for posts.
if ( 'my_post_type' !== $post->post_type ) {
return $allowed_block_types;
}
// Add a classic block.
global $initial_edits;
$initial_edits = array(
'title' => $post->post_title,
'content' => $post->post_content ? $post->post_content : '<p>Add content here</p>',
'excerpt' => $post->post_excerpt,
);
// Return whatever allowed blocks was.
return $allowed_block_types;
}
To support the default classic Gutenberg block for some post types, add the following code snippet to your functions.php
file:
<?php
add_filter( 'allowed_block_types', 'wps_enable_gutenberg_classic_block_for_some_post_types', 10, 2 );
/**
* Adds a default Classic block if no default content exists for a specific set of post types.
*
* @param bool|array $allowed_block_types Array of block type slugs, or
* boolean to enable/disable all.
* @param \WP_Post $post The post resource data.
*
* @return bool|array
*/
function wps_enable_gutenberg_classic_block_for_some_post_types( $allowed_block_types, $post ) {
// If not our post type, bail.
// Change [ 'post', 'page', ] to be whatever post types you want.
if ( ! in_array( $post->post_type, [ 'post', 'page', ], true ) ) {
return $allowed_block_types;
}
// Add a classic block.
global $initial_edits;
$initial_edits = array(
'title' => $post->post_title,
'content' => $post->post_content ? $post->post_content : '<p>Add content here</p>',
'excerpt' => $post->post_excerpt,
);
// Return whatever allowed blocks was.
return $allowed_block_types;
}
To support the default classic Gutenberg block for all post types, add the following code snippet to your functions.php
file:
<?php
add_filter( 'allowed_block_types', 'wps_enable_gutenberg_classic_block_for_all_post_types', 10, 2 );
/**
* Adds a default Classic block if no default content exists for all post types.
*
* @param bool|array $allowed_block_types Array of block type slugs, or
* boolean to enable/disable all.
* @param \WP_Post $post The post resource data.
*
* @return bool|array
*/
function wps_enable_gutenberg_classic_block_for_all_post_types( $allowed_block_types, $post ) {
// Add a classic block.
global $initial_edits;
$initial_edits = array(
'title' => $post->post_title,
'content' => $post->post_content ? $post->post_content : '<p>Add content here</p>',
'excerpt' => $post->post_excerpt,
);
// Return whatever allowed blocks was.
return $allowed_block_types;
}