Adding Gutenberg support to WordPress theme

WordPress 5.0 shipped with a brand new, block-based content editor named Gutenberg. It is a huge improvement for content editing, and will become even more powerful as more blocks are built in core and in plugins.

All WordPress themes work with Gutenberg. It’s simply a new interface for creating content.  No changes are required to your theme to display your new block-based content.

However, there are some new features that your theme can take advantage of with minor updates. Also, the content editing experience can be improved with additional styling in the theme to ensure the backend block editor matches the frontend styling of the theme. 

I’ll guide you through updating your current WordPress theme to support these new features. If you’re not a developer and need help, I recommend you use Codeable – they are fast, knowledgeable, and affordable.

Developer's Guide to Gutenberg

I walk you through the technical details and code snippets you need as a WordPress developer building a Gutenberg website.

Read More

Frontend Styles

You likely have styles for many of these items (blockquotes, horizontal rules), but Gutenberg loads its own styles. You may need additional styles and specificity to ensure consistency.

Turn on wide images

Users can now have “wide” and “full” image alignments if your theme supports it. This allows the image to expand beyond the wrapping content area. You can see an example on my About page.

To add support, simply include this in your theme’s functions.php file:

add_theme_support( 'align-wide' );

It’s up to your theme to style these alignments. See my guide to wide and full image alignment in Gutenberg.

Blockquotes

Gutenberg includes two types of blockquote blocks: a standard blockquote and “large” one. It also includes a “pull quote” blockquote which is designed to be smaller and floated in the content.

All quotes can include a citation, using the <cite> element.

Here’s some base styling I use for these elements (using SASS):

/* Blockquote
--------------------------------------------- */
blockquote,
blockquote.wp-block-quote {
background: transparent;
text-align: left;
p {
font-size: 24px;
font-style: normal;
font-weight: 400;
}
cite,
.wp-block-quote__citation {
display: block;
font-size: 16px;
font-weight: 700;
margin-top: 12px;
text-transform: uppercase;
}
p:last-of-type {
margin-bottom: 0;
}
&.is-large,
&.is-style-large {
margin: calc( 2 * $block-margin ) auto;
p {
@include font-sizes( 24px, 36px );
}
}
}
/* Pull Quote
--------------------------------------------- */
.wp-block-pullquote {
border: none;
padding: 0;
blockquote {
border-left: 0;
border-top: 8px solid $highlight;
border-bottom: 8px solid $highlight;
padding: 16px 0;
text-align: center;
max-width: 50%;
margin: 0 auto;
}
&.alignleft,
&.alignright {
blockquote {
max-width: 100%;
}
}
}
view raw _blocks.scss hosted with ❤ by GitHub

Horizontal Rules

There’s a horizontal rule with its own class ( hr.wp-block-separator), so you should make that match your theme’s standard horizontal rule. There’s a few different styles of horizontal rules built into the editor: default, dots, and wide. Here’s the base SCSS I’m currently using:

/* Separator
--------------------------------------------- */
.wp-block-separator,
hr {
&:not(.is-style-dots) {
background-color: $border-color;
border: 0;
height: 1px;
}
&:not(.is-style-wide):not(.is-style-dots) {
width: 100%;
height: 4px;
background: transparent;
&::before {
content: '';
display: block;
height: 4px;
width: 40px;
background: $highlight;
}
}
&.is-style-dots:before {
color: $grey_9;
font-size: 18px;
letter-spacing: 12px;
padding-left: 12px;
}
}
view raw _blocks.scss hosted with ❤ by GitHub

Buttons

Gutenberg has a button block with its own default styling applied. You’ll likely want to customize this to match your theme’s button styles.

For more information, see my Guide to Color Palettes and Button Styling.

/* Button
--------------------------------------------- */
.wp-block-button {
.wp-block-button__link {
border-radius: 0;
font-weight: 700;
font-size: 16px;
line-height: 18px;
padding: 20px 24px;
&:hover {
background: darken( $highlight, 10% );
text-decoration: none;
}
}
}
view raw _blocks.scss hosted with ❤ by GitHub

Backend Styles

There are two ways you can add your theme styles to the Gutenberg block editor.

Option 1: Editor Styles

Your theme likely has editor styles added to make the classic editor more closely resemble the frontend. By default these are not loaded in Gutenberg, but you can turn it on.

WordPress is smart enough to automatically transform your styles so they only affect the block editor. With this approach, you can define a single set of styles that apply to both the classic and block editors. This is my preferred approach.

// Editor Styles
add_theme_support( 'editor-styles' );
add_editor_style( 'assets/css/editor-style.css' );

The add_theme_support( 'editor-styles' ); tells WordPress to load the editor styles in the Gutenberg block editor. Without this, they would only load in the classic editor (TinyMCE).

The second line, add_editor_style(), is the path to your editor stylesheet.

See my base theme as an example.

Option 2: Enqueue Block Editor Assets

You can enqueue your own styles & scripts in Gutenberg using the enqueue_block_editor_assets hook. This works the same as loading styles & scripts on the frontend using wp_enqueue_scripts.

Do not load your entire frontend stylesheet in Gutenberg. You should only load relevant styles, and prepend them all with the .editor-block-list__block class to ensure it only applies to the editor (not the WP backend menu, metaboxes…).

SASS

Whichever approach you choose, I recommend using SASS partials. This will let you write your styles once and compile them into both the frontend and block editor stylesheets as necessary.

Here’s my main.scss file, which generates the main css file on the frontend, and my editor-style.scss file, which generates a CSS file for loading in Gutenberg.

  • I’m only including relevant styles from the main stylesheet (style-guide and blocks)
  • I have a gutenberg partial for Gutenberg-specific styles – styles that shouldn’t appear on the frontend. I’m using this to “undo” certain styles Gutenberg adds to elements, so those elements match my frontend.
  • In the Gutenberg partial I’m setting the max width of blocks to match the site’s max width on the frontend ($content-width is defined in _base.scss)

Complex Templates

For modular templates that cannot be built with a single editor, I disable both Gutenberg and the classic editor, then build the editing screen with metaboxes.

I’ve found that Gutenberg drastically increases what we can build with the “standard” page template. Before Gutenberg, we would often build 5-8 custom page templates that required metaboxes. Now, almost all of these are built with Gutenberg.

But sometimes certain pages like the homepage and landing pages can be too complicated to rely on Gutenberg currently. 

My website is built 100% with Gutenberg – even the homepage uses the block editor. 

For more advanced templates you can build custom blocks with Advanced Custom Fields (my recommendation), or with JavaScript. You can also leverage block libraries like Atomic Blocks and Jetpack for additional block options.

Any more tips?

Do you have any recommendations for making custom themes more Gutenberg-ready?

Gutenberg Block Editor WordPress Development

Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk

Reader Interactions

Comments

  1. Marcy Diaz says

    I was just beginning to look into what would be needed to convert to Gutenberg. So this was perfect timing. Thank you, Bill!

  2. Theresa Wagar says

    Wow! I see a lot of work coming to make sure all my client sites can co-exist with Gutenburg. Thanks for the detailed start.

  3. Shrinivas says

    Hi Bill, thank you for sharing the note on customizing gutenberg, it’s really gonna help me to start with gutenberg.

  4. Matt Ryan says

    I just received my first request from a client asking that I do some testing to ensure the custom theme we developed for them is WP 5.0 / Gutenberg compatible. This post will form the basis of our action plan to set up a testing and validation process.

    Many thanks for this Bill. Well done.

  5. Jay says

    Great read. Found this particularly funny given the circumstances…

    “Clients will appreciate the effort to future-proof their site”

    Future-proof, at least until the next time WordPress decides to make breaking changes. 😉

    • Bill Erickson says

      You could use anything you like. It’s expected that the .alignwide class be some amount wider than the content area, and I picked half the distance between the left/right edge of the screen and the content area.

      For the .alignfull class, the left/right margin of calc( 50% - 50vw) makes it expand the full width of the screen. Technically, it adds negative left/right margin equal to the space between the left/right side of the screen and the content area.

      For the .alignwide, I cut this in half. calc( 25% - 25vw) makes the image take up half the gap between the left/right side of the screen and the content area.

  6. Clay Teller says

    Hey Bill, thanks, this is great stuff. I’ve made heavy use of ACF Pro in a theme I’m currently developing, mainly for the “flexible content” fields. I know you’ve worked with ACF Pro in the past, so thought I would ask: Do you know if Gutenberg “blocks” will allow me to completely move away from a plugin like ACF, giving me the ability to add my own custom “blocks” to do what “flexible content” field allow me to do? If so, I would love to start transitioning completely away from using a plugin like ACF Pro or CMB2. Hoping this isn’t too specific a question for this post. Thanks!

    • Bill Erickson says

      While it’s theoretically possible, it would likely require orders of magnitude more time to build (think 10-100x the time you spend with ACF). A better comparison would be building your own custom metabox with its flexible content field from scratch, except you’re doing it in JavaScript, a language with which you might not be as familiar.

      I think most developers will use ACF or a similar plugin to create custom blocks, in the same way you use ACF now to create custom metaboxes. For now, I’m still using custom metaboxes for complex pages like this and disabling Gutenberg just on those templates.

  7. Hans says

    Very helpful, thank you Bill.

    I’m looking forward to Gutenberg, but it’s a big change. Some flexibility of it might not be that desirable (like plugins like The Events Calendar Allowing to shift their structured content blocks to other places in each separate post instead of presenting a predictable user experience), but it is nice to have options for when it is needed.

    One thing I especially wonder is how it will work regarding responsiveness. I would imagine that at least all size- and visibility-related attributes of blocks and text may need different settings for different device-sizes. Page builders tend to have attributes to select on which devices (large, medium, small) each block is shown and at what size and themes deliver that in a structural way, but when the content editor allows that to be changed, without that kind of responsiveness options, than small devices may not get an optimal experience. I imagine that might still be developed , since it is an obvious requirement, but it is something I’m too looking for.

    Images is an obvious subject there, since testing tools advice on compressing images and using smaller file-sizes on smaller displays. I have found it to be an increasing complicated subject in the responsive era and standard themes often seem to just use larger images for all displays, like it seems this website does too. I wonder how having users grow and shrink images at will in a page/content builder like Gutenberg will impact image delivery and related source-code and if that will be a subject for WordPress core or theme-developers to solve.

    Thanks,

    Hans

    • Bill Erickson says

      The blocks themselves come with their own styling to ensure they work well across all devices. For instance, a pull quote appears full width on mobile but floated to the left or right on tablet and desktop.

      Beyond the ability to add custom CSS classes to blocks, I don’t think there’s any plan for providing options to control the look at different break points. It’s up to the theme developer to style those blocks effectively.

      This is a good example of why page builder plugins are not going away. They’ll likely shift to providing users more options in the Gutenberg editor.

      To your question regarding images, this is why WordPress has built-in support for srcset. Users can insert an image, and along with it include a list of smaller images the browser can use if they are a better fit.

      As a theme developer, the best thing you can do is ensure all (or most) of your custom image sizes use the same aspect ratio so there’s multiple sizes in the srcset.

      • Hans says

        Thanks for the reaction, Bill. I know of the srcset support of WordPress, but that only adds like your last sentence says images with the same aspect ratio to the srcset, and when the design isn’t based on that and the mobile view needs another ratio ( f.i. because on mobile a background-image of a cta or title would need more height on mobile phones) then one needs to fiddle still and the default srcset of wordpress isn’t enough.

        Plugins like Woocommerce also might decide to change the way they crop images (or in case of woo not allow to crop single product images) and change the rules again. But we have to cope.

        By the way there is discussion going on Gutenberg in GitHub about adding a wrapper block to insert responsiveness to the editor, so the community is actively thinking about this problem and might yet present an answer. To not do so, would decrease the usability of some options it provides. The wrapper block would helas mean responsiveness would be implemented by replicating all blocks for each breakpoint and use display:none to regulate which is shown, so it’s an easy coding solution, but not very elegant or lean.

        The solution of having the theme handle responsiveness might be challenged by the fact that Gutenberg allows to set font-sizes and such by the editor and adds a “style=…” attribute to the element to implement this. Since now that is inline styling (high priority) and users can change image-sizes and font-sizes at will, the theme can no longer easily control how everything is presented.

        That’s why page builders need to be quite complete in the options of each element to be usable. The builder basically replaces the theme’s functionality for the ui-element. I don’t know how all that inline styling will effect SEO, not to speak about duplicating lots of content when wrapper blocks are implemented for responsiveness, but Gutenberg will most likely move some control from the theme to the editor and in the end visions that visitors themselves will control how they want to see modules on their display, making unclear what roles themes will have (if any) in that future. It’s a step unto new territory. Exiting times.

        Page builders will probably decide whether to adopt the editor in their page building ways, or find a way to keep using their own version and interface. Since lots of them are front-end editors by now, it will probably be both if they want to keep using an admin-editor too.

        Given Gutenberg i would imagine that lots of new elements will be provided by others too, especially the plugins that now provide them by shortcodes, hopefully will shift to Gutenberg. But there are offcourse still many (see reviews of the Gutenberg plugin) that don’t like what Gutenberg is doing and want to keep just a non-WYSIWYG text-editor.

        We’ll see. Right now, I welcome Gutenberg and the vision of the drivers of it.

  8. Taylor says

    Thanks for all your Gutenberg posts. I’m updating my starter theme in preparation and I’ve found your posts helpful.

    Two questions about the full-width alignment.

    In the back-end, Gutenberg seems to style the align-full to grow an image if it is too small. Using these align-full styles, images only grow up to their 100%. Gutenberg has it easy though because the back-end editor isn’t inside of a max-width box.

    Second, any solution I’ve found (regardless of over-scaling the images or not) results in a horizontal scrollbar because vw includes the vertical scrollbar if present. It’s not present in demos that don’t induce the scrollbar. You can do things like calc( 100vw – 17px ) to accommodate it, but it’s not even constant and will be less than full-width if there doesn’t happen to be a scrollbar.

    Have you come across that? I almost always do a max-width container for all the page content, but this makes me wonder if instead the descendants of the main content area should get the max-width instead (except for full-width ones, of course).

    • Sal Ferrarello says

      Hi Taylor and Bill,

      I’m having this same problem with a horizontal scroll bar appearing (if the content is long enough to trigger a vertical scroll bar). I’ve found that wrapping everything in a div and setting overflow:hidden; eliminates the vertical scroll bar (in Genesis I’m using the div.site-container element for this). I don’t love this solution but it is the best I’ve found thus far. I’ve written a blog post about this at https://salferrarello.com/full-screen-width-image-inside-container/.

      Thanks for this post Bill, it’s been a great help.

  9. Taylor says

    I forgot to mention — the above scrollbar behavior is visible once you remove gutenberg’s width: content-fit rule which is in effect here on image blocks, but not well-supported.

  10. Joost says

    Thanks for your post. Still wondering if ‘now’ would be a smart moment to get a new theme for my blog, or if it is better to wait until Gutenberg has arrived.

    • Bill Erickson says

      I think now is a great time to get a new theme, as long as the developer is familiar with Gutenberg and has included Gutenberg support, or if it’s a commercial theme and they provide updates that will include Gutenberg support.

      If you’re having a theme custom designed, it takes times (see our sample timeline). Any projects that we book right now will likely start development after Gutenberg comes out. Development is the third stage of Reply

  11. Hans Schuijff says

    I’ve just read your page on modular templates and was impressed with the functionality you offer that way and the user experience. A page builder alike experience, but within the constrains of a theme’s design, even making sure the content stays available for search and changing themes (like BB does). I follow you in that migrating to Gutenberg, at some point, will be a possibility, when limiting the options that are accessible to what the theme supports. So great example of how to do it, and your customers will surely be glad they found you.

    If Gutenberg doesn’t offer adaptations for different viewport sizes (show/not show, size-adaptations, and so fort ), supporting breakpoints or something better, that would perhaps also be the way to go to guarantee the best presentation on all devices. I understand it is already possible, or will be, to limit the options presented in the editor per block to content creators, from within the theme.

    I expect you are also right predicting further tools for easy and fast block creation.

    I like the wide and full display of images, are there next to align-wide, more options that need their theme-support explicitly declared?

    I also like the extra block-types that are offered standard in Gutenberg, like an image with a title on top, even with a fixed background by only switching a checkbox. Not a difficult thing to make, but having it as a standard block-type is a nice thing, even when there are not that many options (like for changing colors also for different states of buttons) and one may want to use a stylesheet still to adapt it to a theme. But even the default presentation looks quite nice.

    Being able to change the HTML on a block level is a much better experience than having to scroll through a long document just to add a class to something.

    So props to Gutenberg for rocking our world in a good way, enabling a change that can again excite our imagination.

    Thanks for the great examples,

    Hans

    • Bill Erickson says

      The only two Gutenberg features that require theme-support (that I know of) are wide images and color options. You can specify an array of theme colors that appear anywhere a user can pick a color (button background, text color…).

  12. Jennifer says

    Hi Bill, thank thanks a bunch for sharing this great examples. Highest time to check Gutenberg Editor. We hope that it comes with a lot of additional values for our customers. Your tipps are very helpful to dig into Themedevelopment with Gutenberg and help me to make a good part with Gutenberg

  13. Bjornen says

    Is this still relevant and accurate? Meaning; if I add this to my theme, Gutenberg will work?
    My theme is set to a custom width of 1200px.

    • Bill Erickson says

      Some of the blockquote and separator styles have changed a bit, but for the most part, this is still accurate.

      I recommend you install the Gutenberg plugin either locally or on a staging environment and then begin making style changes to get them right.

      I’m building a Gutenberg website right now on Genesis, so will be updating my Genesis child theme over the next few weeks with more Gutenberg updates.

      I’m also writing a new blog post, “Building a Gutenberg theme”, which should be out in a few weeks. If you haven’t already, sign up for email updates so you’ll be notified when that post is live 🙂

  14. Phil says

    Thanks a lot for this excellent post – still very relevant, IMHO.
    One thing I haven’t found much info about – Gutenberg does add quite specific styles to its Column element, eg

    @media (min-width:782px) {
    .wp-block-column:not(:first-child){
    padding-left:16px
    }
    .wp-block-column:not(:last-child) {
    padding-right: 16px
    }
    }

    I wonder if the idea here is to use custom CSS classes to override these settings if/when we need different @media sizes or padding/margin values.

    If there’s a simple way to stop Gutenberg loading these styles, at least in the front end, I haven’t found it yet.

  15. Philip Whitneyh says

    Guttenberg will never survive. It is a disaster. There’s enough bugs in it to consumer every ounce of flesh on this earth. It is “like a box of chocolates and has been for the last 4 month

    • Paul says

      I wouldn’t mind it but the developers seem really closed to criticism. I suggested they should make it more intuitive and the reply I got was very defensive. Reading through some of their replies to other suggestions made me skeptical this is going to work out well for everyone…

  16. Jane says

    Thanks for explaining the blockquote blocks and options! Gutenberg partially converted my blockquotes, but not fully (style elements are missing), and now I have a better idea of how to fix them.

  17. Muskie says

    I’m trying to get tall skinny images to float to the right and they do so in the editor as I expected but in my theme they do not float around the next block. I have been looking for some CSS to solve this of course.

  18. mfs says

    re: “Do not load your entire frontend stylesheet in Gutenberg. You should only load relevant styles, and prepend them all with the .editor-block-list__block class to ensure it only applies to the editor (not the WP backend menu, metaboxes…).”

    Makes sense. But have you seen SASS being used to do this? Or maybe I’m not quite getting “it” yet as I’m just finally climbing the Gutenberg learning curve?

    For example, the WP.org tutorial starts with a simple text block. It then shows how to do add an editor style, as well as a frontend style. But, at least in theory aren’t they ideally the same (or damn close)? That is, if the user were to set the font size to e.g. 30px, in a particular font, isn’t the idea that Gutenberg is a true WYSIWYG?

    Unless I’m not finding something yet, a block is going to have two style sheets, and despite the fact there are (nearly) identical, the developer has to maintain both (with the editor css having .editor-block-list__block prefixed. )

    tia –
    mfs

    • Bill Erickson says

      Yes, you can use SASS with either option listed above (using editor styles or loading a separate stylesheet).

      The benefit to the editor style’s approach is WordPress auto-prefixes everything for you as needed so you can start with a cleaner stylesheet.

      Take a look at my two starter themes. The editor stylesheet only contains a few partials:

      @import "partials/base";
      @import "partials/blocks";
      @import "partials/gutenberg";
      

      While the main site’s stylesheet contains those and many others:

      @import "partials/base";
      @import "partials/reset";
      @import "partials/form";
      @import "partials/blocks";
      @import "partials/layout";
      @import "partials/site-header";
      @import "partials/navigation";
      @import "partials/archive";
      @import "partials/singular";
      @import "partials/site-footer";
      

      I only write the relevant styles once. If I’m styling the “button” block, that goes in _blocks.scss which is loaded in both editor-style.css and main.css.

Leave A Reply