How can I make the format styles dropdown in the classic editor apply to ONLY the selected text? Right now it is applying to the nearest line break from the selected text, I don't like that.

Here is the code in my functions.php file:

function add_style_select_buttons( $buttons ) {
    array_unshift( $buttons, 'styleselect' );
    return $buttons;

add_filter( 'mce_buttons_2', 'add_style_select_buttons' );

function my_custom_styles( $init_array ) {  

    $style_formats = array(  

            'title' => 'Fancy Words',  
            'block' => 'div',  
            'classes' => 'fancywords',
            'wrapper' => true,

    $init_array['style_formats'] = json_encode( $style_formats );  

    return $init_array;  

add_filter( 'tiny_mce_before_init', 'my_custom_styles' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.