Created
April 6, 2016 23:34
-
-
Save troutacular/9bdbaa39713c67e0bd01ba8e41c89e2c to your computer and use it in GitHub Desktop.
WordPress TinyMCE sample
This file contains hidden or 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
| // Callback function to insert 'styleselect' into the $buttons array | |
| function my_mce_buttons_2( $buttons ) { | |
| array_unshift( $buttons, 'styleselect' ); | |
| return $buttons; | |
| } | |
| // Register our callback to the appropriate filter | |
| add_filter('mce_buttons_2', 'my_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 | |
| array( | |
| 'title' => 'Blue Box', | |
| 'block' => 'div', | |
| 'classes' => 'blue_box', | |
| 'wrapper' => true, | |
| ), | |
| array( | |
| 'title' => 'Green Box', | |
| 'block' => 'div', | |
| 'classes' => 'green_box', | |
| 'wrapper' => true, | |
| ), | |
| array( | |
| 'title' => 'Orange Box', | |
| 'block' => 'div', | |
| 'classes' => 'orange_box', | |
| 'wrapper' => true, | |
| ), | |
| array( | |
| 'title' => 'Purple Box', | |
| 'block' => 'div', | |
| 'classes' => 'purple_box', | |
| '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