Block Editor PHP Beginner

Load Your Theme’s Styles in the Editor

Make the block editor look like the front end in a classic theme, by loading an editor stylesheet.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 6 lines
add_action( 'after_setup_theme', function (): void {
	add_theme_support( 'editor-styles' );

	// Path relative to the active (child) theme folder.
	add_editor_style( 'assets/css/editor.css' );
} );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

When the editor shows plain default fonts and colours, what writers see doesn’t match the published page. Classic themes can fix that by loading an editor stylesheet.

How it works

add_theme_support( 'editor-styles' ) tells WordPress to apply your stylesheet to the editor canvas. add_editor_style() adds the file. WordPress automatically scopes its rules to the editor content, so a rule for body or h2 only affects the canvas, not the editor interface around it.

Things to watch

  • Create the CSS file in your child theme. Start by copying your theme’s typography and colour rules into it.
  • Block themes load their styles in the editor automatically, so they don’t need this.

How to test it

Open a post in the editor. Headings and paragraphs should use your theme’s fonts and colours.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only