Make the appearance of WordPress block editor consistent with the front-end design!
As a WordPress user, do you often need to open two tabs at the same time for article editing? One tab shows the new Gutenberg block editor, and the other previews the front-end effect of the article to ensure that the final rendering is not wrong?
WordPress theme styles only affect the front end of the website, and backend editors are usually very different from the front end. But this is not unchangeable! With a custom stylesheet, you can make the WordPress editor mirror the front-end look almost perfectly.
This takes only two simple steps:
- Add a few lines of PHP code to the theme's
functions.php
file to inform the editor to load the custom stylesheet. - Create and configure this custom style sheet.
Let's start!
Step 1: Modify functions.php
file
If you are using a non-self-developed WordPress theme, it is highly recommended that you create a sub-theme before making any modifications to the main theme.
Open the theme's functions.php
file (usually located in the root directory of the theme folder) and add the following code at the end of the file:
// Gutenberg custom stylesheet add_theme_support('editor-styles'); add_editor_style( 'editor-style.css' ); // Make sure the path is correctly pointing to the stylesheet file
This code tells WordPress that you support using custom stylesheets to work with Gutenberg and specifies the location of the stylesheet file ( editor-style.css
).
Step 2: Write CSS Style
Now, we enter the CSS writing process.
Due to the wide variety of WordPress themes, it is impossible to write a style sheet that works for all themes. The following example is based on the topics used by my website and hopefully helps you understand how to build style sheets for your website. At the end of the article, a template will be provided to help you get started quickly.
Create a new file named editor-style.css
and place it in the root directory of the theme (or child theme directory).
The CSS style of the block editor is slightly different from the standard CSS. For example, the following code cannot correctly apply text size in an article:
h2 { font-size: 1.75em; }
To set the style correctly, you need to locate the blocks in the block editor. This means<h2></h2>
Elements need to be scoped using .rich-text.block-editor-rich-text__editable
class:
h2.rich-text.block-editor-rich-text__editable { font-size: 1.75em; }
I've created a base CSS file that follows this pattern to style common block editor elements. You can get the file from GitHub and replace the style to match your theme.
I won't expand the stylesheet build process in detail here, but the template should give you a clear idea. A good starting point is to copy elements from your front-end stylesheet, but you may need to change some element classes so that they apply to the block editor window.
If in doubt, use the browser developer tool to check elements and determine their corresponding class name. The templates for the above links should cover most elements.
Effect display
First, let's take a look at the WordPress editor without a custom stylesheet:
Then, compare my test website front-end:
The difference between the two is significant, right? My test site uses a lot of gradients, custom fonts, button styles, and reference blocks, and the container is not a simple square.
Like it or not, you'll agree that this is a big difference from the default Gutenberg editor UI. This is why I need to open a tab page separately to preview the article.
Now, let's load the custom style and see the effect:
Look! The editor UI now looks almost exactly the same as the front end of my website. Content width, font, color and various elements are consistent with the front end. I even have the same beautiful background as the title of the article!
This means – no longer need to preview in another tab. Isn't it cool?
Keeping WordPress editor consistent with the front-end appearance can greatly improve efficiency. For me, frequently switching tabs to view front-end effects when editing articles will interrupt my thinking, so I prefer to avoid this.
Hope the above steps can help you achieve the same effect!
The above is the detailed content of Getting the WordPress Block Editor to Look Like the Front End Design. For more information, please follow other related articles on the PHP Chinese website!

There's been a run of tools, articles, and resources about color lately. Please allow me to close a few tabs by rounding them up here for your enjoyment.

Robin has covered this before, but I've heard some confusion about it in the past few weeks and saw another person take a stab at explaining it, and I wanted

I absolutely love the design of the Sandwich site. Among many beautiful features are these headlines with rainbow underlines that move as you scroll. It's not

Many popular resume designs are making the most of the available page space by laying sections out in a grid shape. Let’s use CSS Grid to create a layout that

Page reloads are a thing. Sometimes we refresh a page when we think it’s unresponsive, or believe that new content is available. Sometimes we’re just mad at

There is very little guidance on how to organize front-end applications in the world of React. (Just move files around until it “feels right,” lol). The truth

Most of the time you don’t really care about whether a user is actively engaged or temporarily inactive on your application. Inactive, meaning, perhaps they

Wufoo has always been great with integrations. They have integrations with specific apps, like Campaign Monitor, Mailchimp, and Typekit, but they also


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver CS6
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.