Skip to content

Instantly share code, notes, and snippets.

@SiGaCode
Created November 21, 2014 17:53
Show Gist options
  • Save SiGaCode/8d5395bfd65c4b2b7395 to your computer and use it in GitHub Desktop.
Save SiGaCode/8d5395bfd65c4b2b7395 to your computer and use it in GitHub Desktop.
Stop Wordpress editor from stripping your HTML when switching between Visual and text editor or while saving. Be sure to test and keep an eye on conflicts with plugins! https://ikreativ.com/stop-wordpress-removing-html/
// stop wp removing div tags - goes to Functions
function ikreativ_tinymce_fix( $init )
{
// html elements being stripped
$init['extended_valid_elements'] = 'div[*],article[*]';
// don't remove line breaks
$init['remove_linebreaks'] = false;
// convert newline characters to BR
$init['convert_newlines_to_brs'] = true;
// don't remove redundant BR
$init['remove_redundant_brs'] = false;
// pass back to wordpress
return $init;
}
add_filter('tiny_mce_before_init', 'ikreativ_tinymce_fix');
@mattHorrigan
Copy link

In my test this actually removes the entire visual editing toolbar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment