Make WordPress Core

Opened 9 years ago

Closed 5 years ago

#34882 closed enhancement (fixed)

make registered editor stylesheets available to frontend

Reported by: ungestaltbar's profile ungestaltbar Owned by: azaozz's profile azaozz
Milestone: 5.3 Priority: normal
Severity: normal Version: 4.4
Component: TinyMCE Keywords:
Focuses: Cc:


Currently add_editor_style() does not register a style as of theme.php:~1318

function add_editor_style( $stylesheet = 'editor-style.css' ) {
	add_theme_support( 'editor-style' );

	if ( ! is_admin() )

For custom frontend usage of wp_editor, there is currently no way to access any custom stylesheets because they are never registered.

The admin check could be moved to class-wp-editor.php:~564 like

        if (is_admin() ) {
	    $editor_styles = get_editor_stylesheets();
	    if ( ! empty( $editor_styles ) ) {
	            foreach ( $editor_styles as $style ) {
		    $mce_css[] = $style;

That way, one could use 'mce_css' filter to manually add any custom stylesheets back to the array of stylesheets.

Attachments (1)

34882.diff (2.2 KB) - added by azaozz 5 years ago.

Download all attachments as: .zip

Change History (12)

#1 @azaozz
9 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to maybelater
  • Status changed from new to closed

The mce_css filter can be used to add any stylesheets at any time. It is more powerful than add_editor_style() as it doesn't limit the location to the current theme.

Closing as maybelater as mce_css can be used for this.

#2 @SergeyBiryukov
8 years ago

#36985 was marked as a duplicate.

#3 @webmandesign
8 years ago

Adding an editor stylesheet(s) is responsibility of the theme, right?

In that case a plugin using the TinyMCE editor on frontend doesn't know about what editor stylesheets the theme includes. So, using mce_css filter in plugin doesn't make sense really.

Likewise, if the theme wants its editor stylesheets to be frontend available, it should hook to mce_css right from the start. Then what point there is to use add_editor_style()?

I've proposed the way which filters the ! is_admin() conditional inside add_editor_style(), so a theme can use add_editor_style() as usually, while a plugin which uses TinyMCE editor on frontend can hook onto the conditional and change it when needed so it allows theme editor stylesheets in frontend editor.

What do you think about that?

#36985 =>

#4 @webmandesign
8 years ago

  • Keywords has-patch added

Hey, I've just proposed a patch that could help with this issue too.

#5 @azaozz
8 years ago

#36985 was marked as a duplicate.

#6 @azaozz
8 years ago

@webmandesign, I'm not sure if adding another filter there is the best solution. The "patch" proposed by @ungestaltbar in the ticket description looks pretty good too. Seems we should be letting themes register editor stylesheet on the front-end.

The next step would be to find out why is_admin() was added there. Is it a simple optimization (less code to run on every front-end page load) or there was another reason too.

Last edited 8 years ago by azaozz (previous) (diff)

#7 @azaozz
8 years ago

  • Focuses ui administration removed
  • Keywords has-patch removed
  • Milestone set to Future Release
  • Resolution maybelater deleted
  • Status changed from closed to reopened

#8 @webmandesign
8 years ago


The reason why I used a filter is due to the fact that I am not sure why there is the is_admin() check. Might be simple optimization, might be something else. And as I didn't want to break anything, I've used the most flexible solution to this problem without actually changing the original functionality.

Of course, if is_admin() check is not needed there, then I would remove it completely. But I don't know the history of it and don't know how to find out, sorry.

But, please, keep in mind that the solution proposed in this ticket would mean a theme author needs to register the editor stylesheets twice. Once in add_editor_style() and second time with mce_css filter. This is a bit too tedious and brings a question why should we use add_editor_style() first place. I've described this in my previous comment.



#9 @azaozz
5 years ago

  • Milestone set to 5.3

Fixing this is not as easy as it looks :)

The add_editor_style() and editor-style.css are specifically for the editor instance on the old Edit Post screen. If we suddenly add these styles to front-end instances of the editor (by removing the is_admin() conditional), chances are something will break or not match well.

On the other hand WP shouldn't prevent plugins to add these editor specific styles to front-end instances, even if not specifically tested by the theme. Thinking the solution proposed in the ticket description is preferable. It allows themes to always register editor-style.css, and plugins to decide where to add it.

Patch coming up.

5 years ago

#10 @azaozz
5 years ago

In 34882.diff: move the is_admin() check from add_editor_style() to the building of the init array in class-wp-editor.php as suggested by @ungestaltbar.

#11 @azaozz
5 years ago

  • Owner set to azaozz
  • Resolution set to fixed
  • Status changed from reopened to closed

In 45621:

Editor: Make registered editor stylesheets (editor-style.css) available to the front-end.

Props webmandesign, azaozz.
Fixes #34882.

Note: See TracTickets for help on using tickets.