0815

Du musst dich anmelden um Beiträge und Themen zu erstellen. Einloggen · Registrieren

Automatically Remove Code Mistakes in Posts

Here is a handy trick that will automatically remove basic mistakes in XHTML markup, such as empty paragraphs, inline font styles, and more. Place this function in your functions.php file:

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

Once in place, use the following function call to display your “cleaned” content in the loop:

<?php if (function_exists('clean_bad_content')) clean_bad_content(true); ?>

Note that the clean_bad_content() accepts a boolean argument (true or false) specifying whether or not to print the function output.

Credit: Matt Varone (404 link removed 2015/02/26)




0