Skip to content

Backgrounds

How-to Guides

Technical References

Plugins /

Loading Gutenberg on VIP

The Block Editor (Gutenberg) is the default editor. However, you can switch to the Classic Editor via filters described here.

You can adjust the behavior 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). 

If you do not configure via filters, Gutenberg is the default.

Loading Gutenberg

Loading behavior is controlled by a filter that should be added in your theme/functions.php:

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 and disabled for others:

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 false;
}

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

To disable Gutenberg only for these post IDs, simply reverse true and false in this example.

Post Types

You can enable or disable Gutenberg for certain post types.

Make sure 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: April 23, 2021