apply_filters( 'tiny_mce_before_init', array $mceInit, string $editor_id )

Filters the TinyMCE config before init.


Parameters Parameters

$mceInit

(array) An array with TinyMCE config.

$editor_id

(string) Unique editor identifier, e.g. 'content'. Accepts 'classic-block' when called from block editor's Classic block.


Top ↑

Source Source

File: wp-includes/class-wp-editor.php

View on Trac



Top ↑

Changelog Changelog

Changelog
Version Description
3.3.0 The $editor_id parameter was added.
2.5.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by stevenlinx

    Example migrated from Codex:

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

You must log in before being able to contribute a note or feedback.