X

Automatically close HTML in WYSIWYG

Adding this PHP code to the functions.php of your wordpress theme will automatically close any missing tags when using the WYSIWYG editor.



Code Snippet:


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;
}

Comments  Leave a Reply

  1. Tweets that mention Wordpress Automatically close HTML in WYSIWYG – wpsnipp.com Wordpress code snippets for your blog -- Topsy.com February 7, 2011 at 10:44 am

    […] 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 🙂 […]

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!