Problem with WordPress messing up HTML with P and BR tags.

Maybe you don’t want to disable wpautop but you are sick of WordPress adding <p> and <br /> tags to your included html.

A solution is to open up wp-includes/formatting-functions.php and modify the wpautop function. In this version, you can make wpautop respect any tags you want. Just add them!

Usage

Simply add your tag name inside the variable below, using the same tag-pip-tag format:

//WP Version 2.0.4
function wpautop($pee, $br = 1) {
        $allowedTags = 'table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre| select|fieldset|legend|form|blockquote|address|math|p|h[1-6]';
        $allowedCloseTags = 'option|select|p|li|div|dl|dd|dt|th|pre|td|ul|ol';

//WP Version 2.2.3
function wpautop($pee, $br = 1) {
        $pee = $pee . "\\n"; // just to make things a little easier, pad the end
        $pee = preg_replace('|\\s*|’, “\\n\\n”, $pee);
        // Space things out a little
        $allblocks = ‘(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|map|area|blockquote|address|math|style|input|p|h[1-6]|hr)’;

ATTENTION

If you mess up WordPress and can’t get anything to work, you should have made a backup! Sorry!

Relevant links

WordPress Forums: How do I remove <p> from the_content ?
WordPress Forums: Hey Wordpress STOP Screwing up my HTML in my posts!

6 Responses to “Problem with WordPress messing up HTML with P and BR tags.”

  1. Yeago Says:

    PS. If you are having this problem but are using a version other than 2.0.3, and you’re not PHP-saavy, and want me to re-write your function… please go to your formatting.php and paste me your wpautop function.

  2. noname Says:

    The allowed functions are now in this file as of WP-2.2.2

    wp-includes/kses.php

  3. axa Says:

    USELESS,,,

  4. Yeago Says:

    …totally useless.

    (Unless of course you’re posting HTML, in which case useFUL).

  5. wassup Says:

    hello. i need some online support pls if u can, just 5 minutes. thx.

    ps: u have my e-mail adress in the form (if u have yahoo mess would better)

  6. wordpress中的tinymce问题 at Freeland | 逍遥郡 Says:

    […] 后来我发现原来在wordpress使用tinymce遇到问题的远远不止我一个。比如这里的一些讨论条目挺有用的,其中有的直接关闭tinymce WYSIWYG功能;有的跟我一样对wpautop()这个函数进行了修改(disable_wpautop);有的修改了tinymce的配置,比如关闭cleanup功能: Download the wp-includes/js/tinymce/tiny_mce.js file using an FTP program and use a text editor to change the following (near line 167) from: […]

Leave a Reply

Add to Technorati Favorites

Orlando Web Design by EAI