Archive

Posts Tagged ‘wordpress content filtering’

Disabling Automatic Post and Page Formatting in Wordpress Themes

July 16th, 2009 2 comments

Problem

Sometimes when working on Wordpress powered sites, especially those that require a lot of custom HTML/CSS formatting through the HTML tab of the editing page, you’ll run into instances where the automatic formatting Wordpress uses becomes really annoying. Wordpress runs a filter on the content of your pages and posts that automatically adds in paragraphs where you might not want them sometimes.

Obviously if you’re sticking to writing relatively simple posts without too much formatting, this isn’t a big deal. But if you using a lot of custom CSS styles in your pages to style pages in a more radical way without having to mess with template files, you’ll need a solution that allows you to bypass that automatic formatting.

Solution

There are a few ways to filter your automatic formatting in Wordpress but the following is the best. You need to add a bit of code directly in front of the call to “the_content()” that disables the filtering. So instead of calling the_content like you normally do in a theme page:

<?php the_content(); ?>

…you would add a single filter directly in front of that comment, like so:

<?php remove_filter ('the_content', 'wpautop'); ?> 
<?php the_content(); ?>

That will disable the formatting of the body of your page. Be careful with using this filter tag, as all of the clean formatting that Wordpress normally applies will disappear when you use it. Your best bet is to create a copy of whatever template page you want this to be applied to and rename it so you can select it as a custom template when writing your new page.