Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How do I stop the editor from stripping my <p> tags and "empty (& nbsp;)" divs on pages?

Since @scribu asked for a sample code here it is:




share|improve this question
Sample text? WP version? –  scribu Feb 28 '11 at 4:06
Why the negative points? –  Eeyore Mar 8 '11 at 1:52
just use this plugin its has built in option to auto remove p and br tag wordpress.org/extend/plugins/tinymce-advanced –  user7580 Aug 3 '11 at 10:54

5 Answers 5

1) Try a few different plugins that disable formatting and stop WP's built-in stripping of extra paragraphs and whitespace: http://wordpress.org/extend/plugins/search.php?q=formatting&sort=

2) You can fool WP into adding a paragraph break by using <b>&nbsp;<b/> in the html editor. It's a non-breaking space in <b> tags. You won't be able to see it in the visual editor, so add it in the htnl editor. It's ugly, but it works without needing to fully disable formatting.

3) You can also do this in functions.php and then wrap the text you don't want formated with <!-- noformat on --> and <!-- noformat off --> tags.

function newautop($text)
    $newtext = "";
    $pos = 0;

    $tags = array('<!-- noformat on -->', '<!-- noformat off -->');
    $status = 0;

    while (!(($newpos = strpos($text, $tags[$status], $pos)) === FALSE))
        $sub = substr($text, $pos, $newpos-$pos);

        if ($status)
            $newtext .= $sub;
            $newtext .= convert_chars(wptexturize(wpautop($sub)));      //Apply both functions (faster)

        $pos = $newpos+strlen($tags[$status]);

        $status = $status?0:1;

    $sub = substr($text, $pos, strlen($text)-$pos);

    if ($status)
        $newtext .= $sub;
        $newtext .= convert_chars(wptexturize(wpautop($sub)));      //Apply both functions (faster)

    //To remove the tags
    $newtext = str_replace($tags[0], "", $newtext);
    $newtext = str_replace($tags[1], "", $newtext);

    return $newtext;

function newtexturize($text)
    return $text;   

function new_convert_chars($text)
    return $text;   

remove_filter('the_content', 'wpautop');
add_filter('the_content', 'newautop');

remove_filter('the_content', 'wptexturize');
add_filter('the_content', 'newtexturize');

remove_filter('the_content', 'convert_chars');
add_filter('the_content', 'new_convert_chars');
share|improve this answer

I had problems with TinyMCE Advanced. I struggled with this for a while. Finally discovered a simple solution - Use Shortcodes!

Place this code into functions.php and enter [br] wherever you want a br tag to appear.

add_shortcode("br", "br_tag");

function br_tag(){
share|improve this answer
Haha, that's Wordpress in a nutshell. –  qwerty Nov 27 '12 at 9:39

Add in your functions.php

remove_filter ('the_content', 'wpautop');
remove_filter ('the_excerpt', 'wpautop');

But you have to add no

manually. This tags are not saved in the database.

share|improve this answer

Ik heb tiny advanced geinstalleerd. http://rubayathasan.com/wordpress/plugin/enabling-line-break-in-wordpress/

It does solve the problem, but now I need to enter a double enter to see a single one.

share|improve this answer

If you're going to be adding HTML tags, why not just use the HTML Editor?

share|improve this answer
and how do we do that ? –  halilpazarlama Sep 30 '13 at 10:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.