add_editor_style

函式
add_editor_style ( $stylesheet = 'editor-style.css' )
引數
  • (array|string) $stylesheet Optional. Stylesheet name or array thereof, relative to theme root. Defaults to 'editor-style.css'
    Required:
    Default: 'editor-style.css'
定義位置
相關方法
remove_editor_stylesget_editor_stylesheetswp_register_stylewp_add_editor_classic_theme_styleswp_add_inline_style
引入
3.0.0
棄用
-

add_editor_style: 這個函式用來給WordPress的視覺化編輯器新增自定義樣式: 該函式需要一個引數:樣式表的URL。

新增自定義TinyMCE編輯器樣式表的回撥

引數$stylesheet是樣式表的名稱,相對於主題根。它也接受一個樣式表的陣列。它是可選的,預設為’editor-style.css’。

這個函式會自動新增另一個字首為-rtl的樣式表,例如editor-style-rtl.css。如果該檔案不存在,在新增樣式表到TinyMCE之前,它將被刪除。如果一個樣式表的陣列被傳遞給add_editor_style(),RTL只被新增到第一個樣式表。

從3.4版本開始,TinyMCE主體有.rtl CSS類: 這是一個更好的選擇,使用該類並將任何RTL樣式新增到主樣式表中。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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 );
}
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 ); }
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 );
}

常見問題

FAQs
檢視更多 >