Two format parameters TinyMCE WordPress

Is it possible to adding two format parameters (like ‘h3’ & ‘span’) for one customized style in TinyMCE for WordPress. I want to create a custom style header that looks like this:

 <h3 class="headerclass"><span>Headertitle</span></h3>

I’m using an array in a function in my function.php that look like this:

array(
        'title' => '--Hedaer--',
        'block' => 'h3',
        'classes' => 'headerclass',
    )

Related posts

Leave a Reply

1 comment

  1. Try this. There might be a better way of doing the inline span but I would add it as an additional style to select from the styles dropdown.

    add_filter( 'mce_buttons_2', 'editor_styles' );
    
    function editor_styles( $buttons ) {
        array_unshift( $buttons, 'styleselect' );
        return $buttons;
    }
    
    add_filter( 'tiny_mce_before_init', 'editorstyles_init' );
    
    function editorstyles_init( $settings ) {
    
        $style_formats = array(
    
            array(
                'title' => 'Header',
                'block' => 'h3',
                'classes' => 'headerclass'
            ),
            array(
                'title' => 'Header inline',
                'inline' => 'span'
            ),
        );
    
        $settings['style_formats'] = json_encode( $style_formats );
    
        return $settings;
    
    }