add_editor_style() WordPress Function

The add_editor_style() function allows you to add a custom stylesheet to the WordPress editor. This can be useful if you want to match the styles of the editor to the styles of your theme.

add_editor_style( array|string $stylesheet = 'editor-style.css' ) #

Adds callback for custom TinyMCE editor stylesheets.


Description

The parameter $stylesheet is the name of the stylesheet, relative to the theme root. It also accepts an array of stylesheets. It is optional and defaults to ‘editor-style.css’.

This function automatically adds another stylesheet with -rtl prefix, e.g. editor-style-rtl.css. If that file doesn’t exist, it is removed before adding the stylesheet(s) to TinyMCE. If an array of stylesheets is passed to add_editor_style(), RTL is only added for the first stylesheet.

Since version 3.4 the TinyMCE body has .rtl CSS class. It is a better option to use that class and add any RTL styles to the main stylesheet.


Top ↑

Parameters

$stylesheet

(array|string)(Optional) Stylesheet name or array thereof, relative to theme root. Defaults to 'editor-style.css'

Default value: 'editor-style.css'


Top ↑

More Information

Allows theme developers to link a custom stylesheet file to the TinyMCE visual editor. The function tests for the existence of the relative path(s) given as the $stylesheet argument against the current theme directory and links the file(s) on success. If no $stylesheet argument is specified, the function will test for the existence of the default editor stylesheet file, editor-style.css, against the current theme directory, and link that file on success.

If a child theme is used, both the current child and parent theme directories are tested and both the files with the same relative path are linked with this single call if they are found.

To link a stylesheet file from a location other than the current theme directory, such as under your plugin directory, use a filter attached to the mce_css hook instead.


Top ↑

Source

File: wp-includes/theme.php

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

	add_theme_support( 'editor-style' );

	$editor_styles = (array) $editor_styles;
	$stylesheet    = (array) $stylesheet;

	if ( is_rtl() ) {
		$rtl_stylesheet = str_replace( '.css', '-rtl.css', $stylesheet[0] );
		$stylesheet[]   = $rtl_stylesheet;
	}

	$editor_styles = array_merge( $editor_styles, $stylesheet );
}


Top ↑

Changelog

Changelog
VersionDescription
3.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More