Make WordPress Core

Opened 17 months ago

Last modified 4 weeks ago

#44172 new defect (bug)

TinyMCE style_formats broken for `a` tags

Reported by: Horttcore Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.9.6
Component: TinyMCE Keywords:
Focuses: Cc:
PR Number:


It seems that the link inserter breaks the TinyMCE style formats.
P-tag is working, the link-tag not.

// Custom styles
add_filter( 'mce_buttons_2', function( $buttons ){
    array_unshift( $buttons, 'styleselect' );
    return $buttons;
} );
add_filter( 'tiny_mce_before_init', function($init_array){
    $style_formats = [
        // These are the custom styles
            'title' => 'Button',
            'inline' => 'a',
            'classes' => 'btn',
            'title' => 'P',
            'block' => 'p',
            'classes' => 'largerp',
    // Insert the array, JSON ENCODED, into 'style_formats'
    $init_array['style_formats'] = json_encode( $style_formats );
    return $init_array;
} );

Change History (2)

#1 @pento
6 weeks ago

  • Component changed from Editor to TinyMCE

#2 @azaozz
4 weeks ago

Some more details would be helpful.

Trying to reproduce, TinyMCE inserts an <a> tag with no href when using "Button" from the Formats drop-down. That seems to be the expected behaviour.

Note: See TracTickets for help on using tickets.