WordPress 5.0 and the Block Editor: What You Need to Know

WordPress 5.0 and the block editor: what changes for developers

WordPress 5.0 was released on December 6, 2018, and the new block editor, developed as the Gutenberg plugin, is now the default editor. Instead of one big text field, the content is a sequence of blocks: paragraphs, headings, images, galleries, buttons. For site owners it is a new way to write, for developers it changes how themes style the editor and how custom content is built.

Problem: After updating to 5.0, the editor looks and works differently, and you need to know what to check in themes, plugins and existing content.

Solution: Learn how blocks are stored, give the theme editor styles and wide alignment support, test custom meta boxes, and install the Classic Editor plugin where the new editor is not ready yet.

How blocks are stored

The content is still HTML in post_content. Block boundaries and settings are kept in HTML comments, which the front end does not show:

<!-- wp:paragraph -->
<p>This is a paragraph block.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":42} -->
<figure class="wp-block-image"><img src="/wp-content/uploads/2018/12/photo.jpg" alt="" class="wp-image-42"/></figure>
<!-- /wp:image -->

Old posts have no such comments. In the new editor they open as one “Classic” block with the old TinyMCE toolbar, and nothing is changed until you convert them to blocks yourself. On the front end old posts look exactly as before.

Theme support

<?php
add_action( 'after_setup_theme', function () {
    add_theme_support( 'align-wide' );        // "Wide width" and "Full width" for images and other blocks
    add_theme_support( 'editor-styles' );     // use the theme's editor stylesheet in the block editor
    add_editor_style( 'css/editor-style.css' );
    add_theme_support( 'responsive-embeds' ); // embeds keep their aspect ratio
} );

With wide alignment, the theme also needs CSS for the .alignwide and .alignfull classes on the front end, otherwise the option exists in the editor but does nothing on the site.

Loading assets for blocks

<?php
// Only in the editor: scripts and styles for the editing interface
add_action( 'enqueue_block_editor_assets', function () {
    wp_enqueue_style( 'ha-editor', get_template_directory_uri() . '/css/editor.css', array(), '1.0' );
} );

// In the editor AND on the front end: the styles of your blocks
add_action( 'enqueue_block_assets', function () {
    wp_enqueue_style( 'ha-blocks', get_template_directory_uri() . '/css/blocks.css', array(), '1.0' );
} );

Meta boxes and the Classic Editor

Classic meta boxes still work: they are shown under the content. Meta boxes that rely on TinyMCE events or the old editor’s JavaScript may break, so test every custom field and plugin screen. Custom post types appear in the block editor only when they are registered with 'show_in_rest' => true; without it they keep the classic editor.

If a site is not ready, the official Classic Editor plugin brings back the old editor. It is supported until the end of 2021:

wp plugin install classic-editor --activate

NOTE: Before updating a production site to 5.0, update a copy first and open the most important pages, custom post types and plugin screens in the editor. Most problems come from plugins that add their own buttons or boxes to the old editor.