Codex tools: Log in
Contents |
Allows theme developers to link a custom stylesheet file to the TinyMCE visual editor. The function test the existence of the relative path(s) given as the $stylesheet argument, or of editor-style.css if no argument is specified, against the current theme directory and links the file(s) 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.
Note that the behavior of this function with respect to child themes was changed in Version 3.4 and changed back in Version 3.5, see the Notes section below.
<?php add_editor_style( $stylesheet ); ?>
Add the following to the functions.php file of your theme.
<?php
function my_theme_add_editor_styles() {
add_editor_style( 'custom-editor-style.css' );
}
add_action( 'init', 'my_theme_add_editor_styles' );
?>
Next, create a file named custom-editor-style.css directly under your theme directory. Any CSS rules added to that file will be reflected within the TinyMCE visual editor. The contents of the file might look like this:
body#tinymce.wp-editor {
font-family: Arial, Helvetica, sans-serif;
margin: 10px;
}
body#tinymce.wp-editor a {
color: #4CA6CF;
}
You can reuse the styles from your theme stylesheet file in your custom editor stylesheet file using the @import CSS rule. Working on the previous example, put the following instead into the custom-editor-style.css file.
@import url( 'style.css' );
/* Add overwrites as needed so that the content of the editor field is attractive and not broken */
body { padding: 0; background: #fff; }
If necessary, change 'style.css' to the path to your theme stylesheet, relative to the custom-editor-style.css file.
To link a custom editor stylesheet file based on the post type being edited, you can use the following in the functions.php file of your theme. This assumes the stylesheet files with names in the form of editor-style-{post_type}.css are present directly under your theme directory.
<?php
function my_theme_add_editor_styles() {
global $post;
$post_type = get_post_type( $post->ID );
$editor_style = 'editor-style-' . $post_type . '.css';
add_editor_style( $editor_style );
}
add_action( 'pre_get_posts', 'my_theme_add_editor_styles' );
?>
Note that the pre_get_posts action hook is used to ensure that the post type is already determined but, at the sime time, that TinyMCE has not been configured yet.
add_editor_style() is located in wp-includes/theme.php.
Theme Support:
add_theme_support(),
remove_theme_support(),
current_theme_supports()
Features:
sidebar,
menus,
post-formats,
post-thumbnails,
custom-background,
custom-header,
automatic-feed-links,
content_width,
editor-style
Filters: mce_spellchecker_languages, mce_buttons, mce_buttons_2, mce_buttons_3, mce_buttons_4, mce_css, mce_external_plugins, mce_external_languages, tiny_mce_before_init