3

I created a style sheet

editor-style.css

I want to load this css file using add_editor_style() function,

In my functions.php

function my_theme_add_editor_styles() {
    add_editor_style( 'css/editor-style.css' );
}
add_action( 'after_setup_theme', 'my_theme_add_editor_styles' );

I also tried this solution

add_editor_style is not loading in frontend. Any solution?

1
  • Why does the file have two .css extensions?
    – jetlej
    Jan 10, 2015 at 19:09

4 Answers 4

5

You shouldn't need an action to add an editor style. Simple add the following anywhere in your functions.php:

add_editor_style('css/editor-style.css');
1
  • Thanks much! The WordPress Codex suggests to do it the way @Relax tried. Removing the function and action stuff worked great.
    – ps2goat
    Jun 16, 2015 at 5:42
13

You need to do two things (see additional add_theme_support):

add_theme_support( 'editor-styles' );
add_action('admin_init', 'el_add_editor_styles');

function el_add_editor_styles() {
    add_editor_style( get_template_directory_uri() . '/css/editor-style.css' );
}
5
  • sadly, this is the only answer that actually works. should be at the top and upvoted. Jul 8, 2020 at 12:42
  • 2
    The reason their example is broken is that add_editor_style calls add_theme_support( 'editor-styles' ); for you, but admin_init is too late to declare theme supports. So they should really recommend add_editor_style be hooked earlier, like after_setup_theme or something.
    – Ethan C
    Sep 16, 2020 at 3:40
  • this answer is correct + the absolute path as specified in @Jake answer
    – Pons
    Sep 3, 2021 at 15:27
  • This answer worked. The Accepted answer did not.
    – jchwebdev
    Sep 7, 2022 at 21:32
  • I updated the answer to include an absolute path to editor-style.css
    – Willster
    Sep 13, 2022 at 11:01
3

Use an absolute path for the stylesheet:

add_editor_style( get_template_directory_uri() . '/css/editor-style.css' );
0

For me, this is what worked

add_theme_support( 'editor-styles' );
add_editor_style( 'css/custom-editor-classes.css' );

I didn't need to put the absolute path or use add_action, but I did need to include add_theme_support. I'm guessing this may vary based on parent theme.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.