Skip to content

Instantly share code, notes, and snippets.

@josephspurrier
Last active August 29, 2015 14:04
Show Gist options
  • Save josephspurrier/cd7346343627098a9502 to your computer and use it in GitHub Desktop.
Save josephspurrier/cd7346343627098a9502 to your computer and use it in GitHub Desktop.
Disable the WordPress Editor Cleanup
/**
* Disable the Visual and Text Editor p and br tag modifications when saving
*
* When you call the editor, it will automatically add a filter depending
* on which editor you have open:
* * Text Editor: add_filter('the_editor_content', 'wp_htmledit_pre');
* * Visual Editor: add_filter('the_editor_content', 'wp_richedit_pre');
*
* The only way to stop this is to remove the filter because it's applied.
* The next call after is do_action( 'media_buttons', $editor_id );
* So to remove this, we want to add an action to the media_buttons
* that removes the filters.
*
* You can see which filters are loaded using: global $wp_filter;
*/
function skl_disable_wp_editor_formatting() {
remove_filter('the_editor_content', 'wp_htmledit_pre');
remove_filter('the_editor_content', 'wp_richedit_pre');
}
add_action( 'media_buttons', 'skl_disable_wp_editor_formatting');
/**
* Disable the editor p and br tag modifications when switching
* back and forth between the Visual and Text tabs
*/
function skl_disable_mce_cleanup(array $init) {
$init = array_merge($init, array(
'convert_fonts_to_spans' => false,
'verify_html' => false,
'fix_list_elements' => false,
'forced_root_block' => false,
'invalid_elements' => '',
'invalid_styles' => '',
'keep_styles' => true,
));
return $init;
}
add_action( 'tiny_mce_before_init', 'skl_disable_mce_cleanup');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment