damsean102
10/13/2017 - 1:26 PM

Tiny MCE Custom Styles


add_filter( 'mce_buttons_2', 'my_mce_buttons_2' );
function my_mce_buttons_2( $buttons ) {
    array_unshift( $buttons, 'styleselect' );
    return $buttons;
}

add_filter( 'tiny_mce_before_init', 'my_mce_before_init' );

function my_mce_before_init( $settings ) {

    $style_formats = array(
      array(
        'title' => 'Large Phone Number',
        'inline' => 'span',
        'classes' => 'phone-number__large'
      ),
      array(
        'title' => 'Blue button',
        'selector' => 'a',
        'classes' => 'btn--blue'
      ),
      array(
        'title' => 'Yellow button',
        'selector' => 'a',
        'classes' => 'btn--yellow'
      ),
    );

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

    return $settings;

}

add_action( 'admin_init', 'add_my_editor_style' );

function add_my_editor_style() {
  add_editor_style();
}