Are you looking for a way to automatically close HTML tags in WYSIWYG editor? While there’s probably a plugin for this, we have created a quick code snippet that you can use to automatically close HTML tags in the WYSIWYG editor in WordPress.
Instructions:
All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:
function clean_bad_content($bPrint = false) { global $post; $szPostContent = $post->post_content; $szRemoveFilter = array("~<p[^>]*>\s?</p>~", "~<a[^>]*>\s?</a>~", "~<font[^>]*>~", "~<\/font>~", "~style\=\"[^\"]*\"~", "~<span[^>]*>\s?</span>~"); $szPostContent = preg_replace($szRemoveFilter, '', $szPostContent); $szPostContent = apply_filters('the_content', $szPostContent); if ($bPrint == false) return $szPostContent; else echo $szPostContent; }
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: 27 Best WordPress Plugins that You MUST Use and how to start a blog.
[…] This post was mentioned on Twitter by Enk. and Devox Solutions, WPSNIPP. WPSNIPP said: #wordpress Automatically close HTML in WYSIWYG http://bit.ly/hgYkxX #blog please RT 🙂 […]