• 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(  
    
            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' );

    The text editor wraps correctly with their buttons, why not the visual editor with it’s dropdown styles?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter gusto2

    (@gusto2)

    Okay, I am going to pretend I understand this. I am going to assume “block” is bad and “inline” is what I want.

    I changed 'block' => 'div', to 'inline' => 'div',, now it doesn’t even work. I still need help.

    Thread Starter gusto2

    (@gusto2)

    When I change block to inline and div to span it works, but spans come out plain ugly. Why can’t I keep it div?

    • This reply was modified 4 years, 4 months ago by gusto2.
    Thread Starter gusto2

    (@gusto2)

    Ah, I added display: block; to the style of the spans, now they are not ugly and look just like divs…
    But if there is any way I can have what I want while it formats divs instead of spans, please let me know.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to make “formats” dropdown styles apply to only the selected text?’ is closed to new replies.