Created
March 21, 2018 14:57
-
-
Save adambradford/f21717d8a2749a63eeafc4fed3d56d9a to your computer and use it in GitHub Desktop.
Add a "Formats" drop-down for styling text to the WordPress TinyMCE editor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//* Add this to your functions.php file. Do NOT include the opening php tag | |
//* Add the "Formats" drop-down in the WP editor | |
add_filter( 'mce_buttons_2', 'ab_mce_editor_buttons' ); | |
function ab_mce_editor_buttons( $buttons ) { | |
array_unshift( $buttons, 'styleselect' ); | |
return $buttons; | |
} | |
//* Add styles/classes to the "Formats" drop-down | |
add_filter( 'tiny_mce_before_init', 'ab_mce_before_init' ); | |
function ab_mce_before_init( $settings ) { | |
$style_formats = array( | |
array( | |
'title' => 'Opening Paragraph', | |
'selector' => 'p', | |
'classes' => 'emph1', | |
), | |
array( | |
'title' => 'another style here', | |
'block' => 'div', | |
'classes' => 'alert_box', | |
'wrapper' => true | |
), | |
array( | |
'title' => 'another style here', | |
'inline' => 'span', | |
'styles' => array( | |
'color' => 'red', // or hex value #ff0000 | |
'fontWeight' => 'bold', | |
'textTransform' => 'uppercase' | |
) | |
) | |
); | |
$settings['style_formats'] = json_encode( $style_formats ); | |
return $settings; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment