DISCLAIMER: this post is older than one year and may not be up to date with latest WordPress version.

If like me, you often display some code on your blog, there’s a strong chance that you’ll enjoy today’s recipe: This handy piece of code will automatically replace all content within <pre> and </pre> tags by html entities.

Just paste the following in your functions.php file. Once saved, all your content with <pre> and </pre> tags will be automatically replaced by html entities.

function pre_entities($matches) {
	return str_replace($matches[1],htmlentities($matches[1]),$matches[0]);
}
//to html entities;  assume content is in the "content" variable
$content = preg_replace_callback('/<pre.*?>(.*?)<\/pre>/imsu',pre_entities, $content);

Credits goes to David Walsh for this very cool tip!

By the way, I recently reviewed the new “WpSEO” plugin on CatsWhoBlog so you should definitely take a look!

Tags

One Comment

  1. some of my rss fetched posts have many and tags that r useless but these r destroying the layout and theme

    may u guide me how to remove all tags from post contents ?

    thnx

Leave a Comment

Your email address will not be published. Required fields are marked *