Skip to content

Instantly share code, notes, and snippets.

@wurwal
Created May 16, 2018 10:27
Show Gist options
  • Save wurwal/9a0bd2b3545277988234fdeb8a7ccd72 to your computer and use it in GitHub Desktop.
Save wurwal/9a0bd2b3545277988234fdeb8a7ccd72 to your computer and use it in GitHub Desktop.
/* adding green text formatting to mce editor */
function wpb_mce_buttons_2($buttons) {
array_unshift($buttons, 'styleselect');
return $buttons;
}
add_filter('mce_buttons_2', 'wpb_mce_buttons_2');
/*
* Callback function to filter the MCE settings
*/
function my_mce_before_init_insert_formats( $init_array ) {
// Define the style_formats array
$style_formats = array(
/*
* Each array child is a format with it's own settings
* Notice that each array has title, block, classes, and wrapper arguments
* Title is the label which will be visible in Formats menu
* Block defines whether it is a span, div, selector, or inline style
* Classes allows you to define CSS classes
* Wrapper whether or not to add a new block-level element around any selected elements
*/
array (
'title' => 'Light Green Text',
'inline' => 'span',
'classes' => 'lightgreen',
'wrapper' => true,
),
array (
'title' => 'Dark Green Text',
'inline' => 'span',
'classes' => 'darkgreen',
'wrapper' => true,
)
);
// Insert the array, JSON ENCODED, into 'style_formats'
$init_array['style_formats'] = json_encode( $style_formats );
return $init_array;
}
// Attach callback to 'tiny_mce_before_init'
add_filter( 'tiny_mce_before_init', 'my_mce_before_init_insert_formats' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment