您可以根据需要过滤TinyMCE主体类以添加或更改。它是一个预先填充了post类型等内容的字符串,因此最简单的方法是附加额外的类(使用前面的空格)。
<?php
function wpse_128380_tinymce_body_class( $mce ) {
// you could do things here to detect whatever you need
// and use those for the additional classes.
// be safe and use sanitize_html_class or similar if generated.
// example: use the post ID when editing a post
if ( $post = get_post() ) {
$mce[\'body_class\'] .= \' \' . sanitize_html_class( $post->ID );
}
$mce[\'body_class\'] .= \' custom-class another-custom-class etc\';
return $mce;
}
add_filter( \'tiny_mce_before_init\', \'wpse_128380_tinymce_body_class\' );
// if you\'re using the "teeny" version of the editor,
// it fires the teeny_mce_before_init filter instead.