【问题标题】:WordPress: Add custom style in <p>-tag in TinyMCE EditorWordPress:在 TinyMCE 编辑器的 <p>-tag 中添加自定义样式
【发布时间】:2021-09-10 20:07:55
【问题描述】:

我想在 TinyMCE 编辑器中为 &lt;p&gt; 标签添加自定义样式。

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

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

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;  

} 

【问题讨论】:

  • 我的猜测是,因为 p 标签不能存在于另一个 p 标签中,它会自动将其作为有效的块选项忽略

标签: php wordpress tinymce editor


【解决方案1】:

我想我找到了解决方案。 段落的包装器必须是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;  

} 

【讨论】:

    猜你喜欢
    • 2013-08-31
    • 1970-01-01
    • 2019-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-27
    相关资源
    最近更新 更多