Created
April 18, 2014 13:12
-
-
Save chssweb/11043563 to your computer and use it in GitHub Desktop.
Modify menus in WP 3.9's new tinymce v4 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 | |
function my_theme_add_editor_styles() { | |
add_editor_style( CHILD_TEMPLATE_DIRECTORY . '/tinymce-style.css'); | |
} | |
add_action( 'init', 'my_theme_add_editor_styles' ); | |
// 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'); | |
function remove_tinymce_buttons1($buttons) | |
{ | |
//Remove the format dropdown select and text color selector | |
$remove = array('strikethrough','hr','underline','aligncenter','alignright','forecolor','charmap','outdent','indent'); | |
return array_diff($buttons,$remove); | |
} | |
add_filter('mce_buttons','remove_tinymce_buttons1'); | |
function remove_tinymce_buttons2($buttons) | |
{ | |
//Remove the format dropdown select and text color selector | |
$remove = array('underline','alignjustify','forecolor','charmap','outdent','indent'); | |
return array_diff($buttons,$remove); | |
} | |
add_filter('mce_buttons_2','remove_tinymce_buttons2'); | |
// Callback function to filter the MCE settings | |
function my_mce_before_init_insert_formats( $init_array ) { | |
// Define the style_formats array | |
$style_formats = array( | |
array( | |
'title' => 'First paragraph', | |
'selector' => 'p', | |
'classes' => 'standFirst', | |
'wrapper' => true, | |
), | |
array( | |
'title' => 'Related links list', | |
'selector' => 'ul,h2,h3,h4', | |
'classes' => 'related-links', | |
'wrapper' => true, | |
), | |
array( | |
'title' => 'Publications links list', | |
'selector' => 'ul,h2,h3,h4', | |
'classes' => 'publications-links', | |
'wrapper' => true, | |
), | |
array( | |
'title' => 'Info [blue] box', | |
'selector' => 'p', | |
'classes' => 'info', | |
'wrapper' => true, | |
), | |
array( | |
'title' => 'Notice [yellow] box', | |
'selector' => 'p', | |
'classes' => 'notice', | |
'wrapper' => true, | |
), | |
array( | |
'title' => 'Success [green] box', | |
'selector' => 'p', | |
'classes' => 'success', | |
'wrapper' => true, | |
), | |
); | |
// Insert the array, JSON ENCODED, into 'style_formats' | |
$init_array['style_formats'] = json_encode( $style_formats ); | |
$init_array['block_formats'] = "Paragraph=p;Header 2=h2;Header 3=h3;Header 4=h4;Header 5=h5"; | |
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