Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Plugin API/Filter Reference/tiny mce before init


This filter grants developers access to the TinyMCE settings array.

It passes 2 arguments: an array of editor settings and the editor id


The following example adds custom style options to an existing Style dropdown.

Note that, by default, the Style dropdown is hidden in WordPress. To show this option, you will need to add it using the mce_buttons_2 filter and load the CSS using the mce_css hook.

function mytheme_tinymce_settings( $settings ) {
	//First, we define the styles we want to add in format 'Style Name' => 'css classes'
	$classes = array(
		__('Test style 1', 'mytheme') => 'teststyle1',
		__('Test style 2', 'mytheme') => 'teststyle2',
		__('Test style 3', 'mytheme') => 'teststyle3',

	//Delimit styles by semicolon in format 'Title=classes;' so TinyMCE can use it
	if ( ! empty( $settings['theme_advanced_styles'] ) ) {
		$settings['theme_advanced_styles'] .= ';';
	} else {
		//If there's nothing defined yet, define it
		$settings['theme_advanced_styles'] = '';

	//Loop through our newly defined classes and add them to TinyMCE
	$class_settings = '';
	foreach ( $classes as $name => $value ) {
		$class_settings .= "{$name}={$value};";

	//Add our new class settings to the TinyMCE $settings array
	$settings['theme_advanced_styles'] .= trim( $class_settings, '; ' );

	return $settings;
add_filter( 'tiny_mce_before_init', 'mytheme_tinymce_settings' );