Created
August 13, 2014 15:36
-
-
Save gmutschler/a703e95e66e491b7423f to your computer and use it in GitHub Desktop.
Customize tinyMCE in wordpress with selfdefined styles
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
.red { | |
color: #89191e; | |
font-weight: bold; | |
} |
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 | |
//Add "Styles" drop-down on the 2nd line | |
function tuts_mce_editor_buttons( $buttons ) { | |
array_unshift( $buttons, 'styleselect' ); | |
return $buttons; | |
} | |
add_filter( 'mce_buttons_2', 'tuts_mce_editor_buttons' ); | |
function tuts_mce_before_init( $settings ) { | |
$style_formats = array( | |
array( | |
'title' => 'red Emphasized', | |
'inline' => 'span', | |
'classes' => 'red', | |
), | |
); | |
$settings['style_formats'] = json_encode( $style_formats ); | |
return $settings; | |
} | |
add_filter( 'tiny_mce_before_init', 'tuts_mce_before_init' ); | |
//Remove the text color selector | |
function myplugin_tinymce_buttons($buttons) { | |
$remove = 'forecolor'; | |
//Find the array key and then unset | |
if ( ( $key = array_search($remove,$buttons) ) !== false ) | |
unset($buttons[$key]); | |
return $buttons; | |
} | |
add_filter('mce_buttons_2','myplugin_tinymce_buttons'); | |
//Include the stylesheet | |
function my_theme_add_editor_styles() { | |
add_editor_style( get_stylesheet_directory_uri() . '/editor-styles.css' ); | |
} | |
add_action( 'init', 'my_theme_add_editor_styles' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment