Skip to content

How-to Guides

Technical References

Plugins /

Gutenberg

For applications created on and after November 18, 2020, the Block Editor (aka Gutenberg) is the default editor.

Gutenberg Ramp Plugin

For applications created prior to November 18, 2020, the Gutenberg Ramp plugin is loaded instead, which disables the block editor by default to allow for an easier transition. That plugin is now deprecated in favor of the WordPress core functionality described in this document. We recommend switching to the core usage as soon as possible.

You can adjust the behaviour of the editor using the filters described in this document. For example, you can load Gutenberg for all posts and post types, or selectively by post ID (load only for specific posts) and post type (load only for specific post types). 

Loading Gutenberg

Loading behavior is controlled by a filter that needs to be added in your theme/functions.php. The filter should be used in this way:

add_filter( 'use_block_editor_for_post', '__return_true'  );

This will affect all post types.

Alternatively, should you not want to load Gutenberg, you can use the filter this way:

add_filter( 'use_block_editor_for_post', '__return_false'  );

Note that if the filter is being used in many places in your code, the priority of the filter might need to be changed.

Post IDs

You can have Gutenberg loaded only for certain posts. To do this, use the filter in the following way:

function maybe_load_gutenberg_for_post_id( $can_edit, $post ) {
     $enable_for_post_ids = [ 100, 200, 300 ];

     if ( in_array( $post->ID, $enable_for_post_ids, true ) ) {
          return true;
     }

     return $can_edit;
}

add_filter( 'use_block_editor_for_post', 'maybe_load_gutenberg_for_post_id', 20, 2 );

To disable Gutenberg for these post IDs, the filter function should return false.

Post Types

You can enable or disable Gutenberg for certain post types.

Make sure that the post type is registered with ‘show_in_rest’ => true otherwise Gutenberg cannot be enabled.

Here is an example of how to load Gutenberg only for certain post types:

function maybe_load_gutenberg_for_post_type( $can_edit, $post ) {
        $enable_for_post_types = [ 'page' ];
        if ( in_array( $post->post_type, $enable_for_post_types, true ) ) {
                return true;
        }
        return false;
}
add_filter( 'use_block_editor_for_post', 'maybe_load_gutenberg_for_post_type', 15, 2 );

Local Development

The above functionality is available via WordPress core so it is available by default on your VIP Go Development Environment.

Last updated: November 18, 2020