2

Steps for problem reproduction:

  1. Open WordPress Admin Dashboard (I use version 3.7);
  2. Click on Page > Add Page;
  3. On the editor, choose the "HTML" Tab;
  4. Write <p>Lorem ipsum dolor sit amet</p><br> on the content area;
  5. Choose the "Visual" Tab;
  6. Choose "HTML" Tab back;
  7. The code <p>Lorem ipsum dolor sit amet</p><br> lost its formatting and appears as:

    Lorem ipsum dolor sit amet
    
    &nbsp;
    

How to deactivate this TinyMCE issue to maintain the entirely original formatting? (I'm looking for a solution on JavaScript client-side of the editor)

3 Answers 3

1

Once you save it, the

tags are automatically added to the contents. It only removes it when you have a plain <p>....</p> but if you have <p class='something'>...</p> it would preserve it.

2
  • Hi iSuthan thanks for the answer! Actually, I think this is not a server-side problem, that is, it doesn't matter whether you save the Post/Page or not, for this to happen. The issue seems to be related with the TinyMCE plugin. It seems that it cannot convert Visual to HTML when you switch tabs back. What I want is to totally disable it or fix it in some way. Commented Oct 29, 2013 at 20:39
  • @João Paulin - check these plugin: wordpress.org/plugins/disable-visual-editor-wysiwyg
    – Maikal
    Commented Sep 4, 2015 at 13:31
1

You can add:

"wpautop" => false

as an argument to your wp_editor.

Example (mileage may vary) :

 $args = array(
                "textarea_name" => $this->option_name . "[editor_text]", // Name of the textarea on the forms, this value is passed when submitting the form.
                "textarea_rows" => 15, // The number of rows textarea displays.
                "wpautop" => false, // So <p> tags are not removed going from text->visual->text in editor.
                "editor_class" => "my_editor_custom_css" // Additional CSS classes added to the TinyMce editor.
            );

        echo wp_editor($display_text, "my_editor_html_id", $args);

Note that you have to use <p> </p> tags rather than <br> but that is the preferred way nowadays anyway since it gives you the capability of formatting with css without touching the html.

0

I do not usually recommend plugins as an answer to something like this, but TinyMCE Advanced is developed by a core WP developer and it provides this option. It's one of my staple plugins on every WP site I create.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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