Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Custom Style WordPress Post Editor: How to Add It

· 7 min read · Home Tech

In this article
  1. What the Editor Style Actually Does
  2. How to Add a Custom Editor Style (Classic Editor)
  3. Adding a Custom Styles Dropdown in TinyMCE
  4. Custom Styles in the Block Editor (Gutenberg)
  5. Common Pitfalls and How to Avoid Them
  6. Choosing Between Editor Styles and Theme.json
  7. Frequently Asked Questions

To add a custom style to the WordPress post editor, you use the add_editor_style() function in your theme’s functions.php file, which tells WordPress to load a separate CSS file (like editor-style.css) that styles the editing screen. You then create that CSS file with your custom rules, and optionally use the tiny_mce_before_init filter to add a "Formats" dropdown for applying those styles to selected text. This gives you full control over the look of the content area without affecting the front end of your site.

What the Editor Style Actually Does

The WordPress post editor (both the classic TinyMCE editor and the newer block editor) has its own default styling that determines how your content looks while you write. By default, the editor uses a generic stylesheet that may not match your theme’s typography, colors, or spacing. Adding a custom editor style replaces or augments that default, so the editing screen reflects your site’s design more closely. This is purely a visual aid for the author—it does not change how the published page looks; that is controlled by your theme’s main stylesheet.

When you add an editor style, WordPress loads it only in the admin area when editing posts or pages. It does not affect the front end, and it does not alter the content itself. The styles you write target the same HTML elements that appear in the editor (like h1, p, blockquote), so you can make headings larger, change the font, or add a background color to pull quotes, for example.

How to Add a Custom Editor Style (Classic Editor)

If you are using the classic editor (or the block editor with the classic paragraph block), the process is straightforward. The add_editor_style() function is part of the WordPress theme API and has been available since WordPress 3.0. Here are the steps:

  1. Create a new CSS file in your theme folder, for example editor-style.css. You can name it anything, but the convention is editor-style.css.
  2. Open your theme’s functions.php file and add the following line, usually inside a function hooked to after_setup_theme:
function mytheme_add_editor_styles() {
    add_editor_style( 'editor-style.css' );
}
add_action( 'after_setup_theme', 'mytheme_add_editor_styles' );

If you are using a child theme, place the CSS file in the child theme folder and call add_editor_style() from the child theme’s functions.php. The path is relative to the theme root, so if you put the file in a subfolder, use add_editor_style( 'css/editor-style.css' ).

Now write your custom CSS in that file. For example, to make all paragraphs in the editor slightly larger and change the heading color:

body { font-size: 16px; }
h1, h2, h3 { color: #333; }

That’s it. The next time you open a post for editing, the styles will be applied to the content area. Note that the editor style only affects the visual editing screen, not the saved content.

Adding a Custom Styles Dropdown in TinyMCE

Beyond just styling the editor background, you can add a "Formats" dropdown that lets authors apply custom classes to selected text. This is useful for creating callout boxes, highlighted text, or button-like links. To do this, you use the tiny_mce_before_init filter to modify the style_formats option.

Here is an example that adds a "Callout" style and a "Highlight" style:

function mytheme_mce_before_init( $settings ) {
    $style_formats = array(
        array(
            'title' => 'Callout',
            'block' => 'div',
            'classes' => 'callout',
            'wrapper' => true
        ),
        array(
            'title' => 'Highlight',
            'inline' => 'span',
            'classes' => 'highlight'
        )
    );
    $settings['style_formats'] = json_encode( $style_formats );
    return $settings;
}
add_filter( 'tiny_mce_before_init', 'mytheme_mce_before_init' );

After adding this, you must also define the .callout and .highlight classes in your editor-style.css (and ideally in your main theme CSS so the front end looks the same). The dropdown will appear in the editor toolbar under "Formats" (the button with an A and a paintbrush icon). This method works only with the classic editor or the classic block; the block editor has a different mechanism (see below).

Custom Styles in the Block Editor (Gutenberg)

The block editor (introduced in WordPress 5.0) does not use add_editor_style() in the same way. Instead, it uses a theme.json file or the add_theme_support('editor-styles') function. To add custom styles to the block editor, you need to do two things:

  1. Add add_theme_support('editor-styles'); to your theme’s functions.php.
  2. Create an editor-style.css file and enqueue it using add_editor_style('editor-style.css'); as before.

However, the block editor uses a different CSS structure. The editor content is wrapped in a .wp-block-post-content class, and each block has its own class names. So your CSS selectors need to target those classes. For example, to style all paragraphs in the block editor, you would write:

.wp-block-post-content p { font-size: 16px; }

To add a custom block style (like a colored button), you register it via the register_block_style function in PHP or via JavaScript. The PHP approach is simpler for theme developers:

function mytheme_register_block_styles() {
    register_block_style( 'core/button', array(
        'name' => 'custom-button',
        'label' => 'Custom Button'
    ) );
}
add_action( 'init', 'mytheme_register_block_styles' );

Then you define the .is-style-custom-button class in your editor-style.css (and front-end CSS). The block editor will show the style in the block’s settings sidebar under "Styles".

Common Pitfalls and How to Avoid Them

Several issues often arise when adding custom editor styles. Here are the most common ones and their solutions:

  • Styles not loading: Make sure the file path is correct and that you have called add_editor_style() inside a function hooked to after_setup_theme. Also, clear any caching plugins or browser cache.
  • Styles only appear in classic editor: If you are using the block editor, you must add add_theme_support('editor-styles') and use block-specific selectors.
  • Styles appear in editor but not on front end: That is expected. The editor style is separate from the theme’s main stylesheet. You need to duplicate the relevant rules in your theme’s style.css (or use the same class names) for the front end to match.
  • Formats dropdown not showing: The style_formats setting only works if the editor is in “Visual” mode and the “Formats” button is enabled. Also, ensure you have defined the classes in your editor-style.css, otherwise the styles will not be visible in the dropdown preview.
  • Child theme issues: If you are using a child theme, always put the editor-style.css file in the child theme folder and call add_editor_style() from the child theme’s functions.php. Parent theme styles will not be automatically inherited.

Choosing Between Editor Styles and Theme.json

For block themes (themes that use theme.json), the recommended way to style the editor is to use the styles section in theme.json. This file allows you to set typography, colors, spacing, and other design tokens that apply to both the editor and the front end. For example, you can set the global font size or heading color in theme.json and it will automatically apply to the block editor. This is more efficient than writing separate CSS.

For classic themes, add_editor_style() remains the standard method. If you are building a hybrid theme (using classic PHP templates but also supporting blocks), you can use both: theme.json for block editor global styles and add_editor_style() for additional custom CSS that applies to both classic and block editors.

Frequently Asked Questions

Does the editor style affect the published page?

No. The editor style is loaded only in the WordPress admin area when editing content. It changes how the content appears in the editing screen, but the published page uses your theme’s front-end stylesheet. If you want the same styles to appear on the front end, you must include them in your main theme CSS.

Can I use a custom style for a specific post type only?

Yes. You can conditionally load the editor style only for certain post types by checking the current screen. For example, in your after_setup_theme function, you can use is_admin() and the get_current_screen() function to detect the post type, then call add_editor_style() only for that post type. However, add_editor_style() must be called during after_setup_theme, so you might need to use a different hook like admin_enqueue_scripts to load a custom CSS file specifically for that post type.

Why is my editor style not showing in the block editor?

The block editor requires add_theme_support('editor-styles') to be declared in your theme. Without that, WordPress will not enqueue the editor-style.css file. Also, ensure your CSS selectors target the block editor’s wrapper (.wp-block-post-content) and block classes, as opposed to the classic editor’s body selector.

How do I add a custom button style in the block editor?

Use the register_block_style function in your theme’s PHP. For example, to add a style to the Button block, you would call register_block_style('core/button', array('name' => 'my-style', 'label' => 'My Style')). Then define the .is-style-my-style class in your editor-style.css and front-end CSS. The style will appear in the block’s settings under “Styles”.

Can I use a plugin to add custom editor styles?

Yes, several plugins provide a user interface for adding custom CSS to the editor without touching code. However, using the built-in theme functions is lighter and gives you full control. If you are not comfortable editing PHP, a plugin like “Custom CSS for Editor” or a page builder that includes editor styling options can achieve similar results.