WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

I know this is a fairly old forum...I've come across many on this issue of visual editor stripping tags when switiching tabs...I simple followed this link: http://rubayathasan.com/reviews/enabling-line-break-in-wordpress/#comment-1349250

and installed TinyMCE Advanced...all is working like a charm and I now have more features to be able to add to my visual editor.

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

Add in your functions.php

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

But you have to add no <p> and <br/> manually. These tags are not saved in the database.

share|improve this answer

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.