Last active
August 29, 2015 14:26
-
-
Save bbmatt/dbc37e7905b319603ec3 to your computer and use it in GitHub Desktop.
Get tinymce to behave with custom styles, blockformats and editor buttons in Wordpress.
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 | |
// Wysiwyg editor configuration (Tiny MCE) | |
function my_format_TinyMCE( $in ) { | |
$in['remove_linebreaks'] = false; | |
$in['gecko_spellcheck'] = false; | |
$in['keep_styles'] = true; | |
$in['accessibility_focus'] = true; | |
$in['tabfocus_elements'] = 'major-publishing-actions'; | |
$in['media_strict'] = false; | |
$in['paste_remove_styles'] = false; | |
$in['paste_remove_spans'] = false; | |
$in['paste_strip_class_attributes'] = 'none'; | |
$in['paste_text_use_dialog'] = true; | |
$in['wpeditimage_disable_captions'] = true; | |
$in['plugins'] = 'tabfocus,paste,media,fullscreen,wordpress,wpeditimage,wpgallery,wplink,wpdialogs,wpfullscreen'; | |
$in['content_css'] = get_template_directory_uri() . "/editor-style.css"; | |
$in['wpautop'] = true; | |
$in['apply_source_formatting'] = false; | |
$in['block_formats'] = "Paragraph=p; Heading 3=h3; Heading 4=h4"; | |
$in['toolbar1'] = 'bold,italic,strikethrough,bullist,numlist,blockquote,hr,link,unlink,wp_more,spellchecker,wp_fullscreen,wp_adv '; | |
$in['toolbar2'] = 'formatselect,styleselect,underline,pastetext,removeformat,charmap,undo,redo,wp_help '; | |
$in['toolbar3'] = ''; | |
$in['toolbar4'] = ''; | |
return $in; | |
} | |
// 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' => 'intro copy', | |
'block' => 'p', | |
'classes' => 'intro', | |
), | |
array( | |
'title' => 'lead copy', | |
'block' => 'p', | |
'classes' => 'lead', | |
), | |
); | |
// Insert the array, JSON ENCODED, into 'style_formats' | |
$init_array['style_formats'] = json_encode( $style_formats ); | |
return $init_array; | |
} | |
// Add our filters | |
add_filter('tiny_mce_before_init', 'my_mce_before_init_insert_formats' ); | |
add_filter('tiny_mce_before_init', 'my_format_TinyMCE' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment