add_editor_style()
最后更新于:2021-11-25 19:10:45
add_editor_style( array|string$stylesheet=’editor-style.css’)Adds callback for custom TinyMCE editor stylesheets.
参数
- $stylesheet
-
(array|string) (Optional) Stylesheet name or array thereof, relative to theme root. Defaults to ‘editor-style.css’
Default value: ‘editor-style.css’
源文件
文件: gc-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 );
}
/** * Registers an editor stylesheet for the current theme. * * @global GC_Post $post Global post object. */ function gcdocs_theme_add_editor_styles() { global $post; $my_post_type = 'posttype'; // New post (init hook). if ( false !== stristr( $_SERVER['REQUEST_URI'], 'post-new.php' ) && ( isset( $_GET['post_type'] ) === true && $my_post_type == $_GET['post_type'] ) ) { add_editor_style( get_stylesheet_directory_uri() . '/css/editor-style-' . $my_post_type . '.css' ); } // Edit post (pre_get_posts hook). if ( stristr( $_SERVER['REQUEST_URI'], 'post.php' ) !== false && is_object( $post ) && $my_post_type == get_post_type( $post->ID ) ) { add_editor_style( get_stylesheet_directory_uri() . '/css/editor-style-' . $my_post_type . '.css' ); } } add_action( 'init', 'gcdocs_theme_add_editor_styles' ); add_action( 'pre_get_posts', 'gcdocs_theme_add_editor_styles' );
function value( $ar, $key, $default = '' ) { if ( is_array( $ar ) && isset( $ar[ $key ] ) ) { return $ar[ $key ]; } //else return $default; } /** * Registers an editor stylesheet for the current theme. * * @global GC_Post $post Global post object. */ function gcdocs_theme_add_editor_styles() { global $pagenow; global $post; $my_post_type = 'posttype'; if ( ( ( 'post-new.php' === $pagenow ) && ( value( $_GET, 'post_type' ) == $my_post_type ) ) || // New post (init hook) ( ( 'post.php' === $pagenow ) && is_object( $post ) && ( get_post_type( $post->ID ) == $my_post_type ) ) ) { // Edit post (pre_get_posts hook). add_editor_style( get_stylesheet_directory_uri() . '/css/editor-style-' . $my_post_type . '.css' ); } } add_action( 'admin_init', 'gcdocs_theme_add_editor_styles' ); add_action( 'pre_get_posts', 'gcdocs_theme_add_editor_styles' );