WordPress:在 TinyMCE 编辑器的 <p>-tag 中添加自定义样式

WordPress: Add custom style in <p>-tag in TinyMCE Editor

我想在 TinyMCE 编辑器中为 <p> 标签添加自定义样式。

我尝试了以下代码。但它不适用于 <p> 标签。如果我改用 <span> 标签,它会起作用吗?!

是否有任何限制或我的代码有问题?

function my_mce_before_init_insert_formats( $init_array ) {  

    $style_formats = array(  
        array(  
            'title' => 'Lead',  
            'block' => 'p', 
            // 'block' => 'span',  <-- works
            'classes' => 'lead',
            'wrapper' => true,
        ),
    );  
    $init_array['style_formats'] = wp_json_encode( $style_formats );  
    
    return $init_array;  

} 

我想我找到了解决办法。 段落的包装器必须是 false

function my_mce_before_init_insert_formats( $init_array ) {  

    $style_formats = array(  
        array(  
            'title' => 'Lead',  
            'block' => 'p', 
            'classes' => 'lead',
            'wrapper' => false,
        ),
    );  
    $init_array['style_formats'] = wp_json_encode( $style_formats );  
    
    return $init_array;  

}