Last active
May 15, 2021 19:44
-
-
Save mattheu/508d3246eea566e6fa33 to your computer and use it in GitHub Desktop.
Tidy Up WordPress TinyMCE 4 editor buttons
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
<?php | |
// Modify Tiny_MCE init | |
add_filter('tiny_mce_before_init', 'tmy_modify_tinyMCE4', 10, 2 ); | |
/** | |
* Filter TinyMCE4 Init args. | |
*/ | |
function tmy_modify_tinyMCE4( $mceInit, $editor_id ) { | |
// Block Formats. | |
// Set custom to prevent authors using H1 tags in the content. | |
$mceInit['block_formats'] = "Paragraph=p;Header 2=h2;Header 3=h3;Preformatted=pre"; | |
$toolbar1 = explode( ',', $mceInit['toolbar1'] ); | |
$toolbar2 = explode( ',', $mceInit['toolbar2'] ); | |
$remove = array( | |
'underline', | |
'forecolor', | |
'alignjustify', | |
'alignleft', | |
'aligncenter', | |
'alignright', | |
'indent', | |
'outdent', | |
'wp_fullscreen', | |
'wp_more', | |
'hr', | |
'strikethrough' | |
); | |
foreach ( $remove as $name ) { | |
if ( $key = array_search( $name, $toolbar1 ) ) { | |
unset( $toolbar1[$key] ); | |
} | |
if ( $key = array_search( $name, $toolbar2 ) ) { | |
unset( $toolbar2[$key] ); | |
} | |
} | |
// Add some back in, but to different locations. | |
array_splice( $toolbar2, 1, 0, 'hr' ); | |
array_splice( $toolbar2, 1, 0, 'strikethrough' ); | |
$mceInit['toolbar1'] = implode( ',', $toolbar1 ); | |
$mceInit['toolbar2'] = implode( ',', $toolbar2 ); | |
return $mceInit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment