Support » Fixing WordPress » Visual Editor Removing Leading Whitespace

  • I am not sure which version of WordPress this started in, but the visual editor likes to remove leading whitespace on every line whenever a post is opened. It used to be that it only did that when you initially pasted text into the editor. So the solution used to be that I would use the text editor and paste the code. Then when switching to the visual editor it would leave my spacing alone. Here is an example of what it is supposed to look like:

    However, when I went in to edit that post in 4.8.3 version of WordPress it automatically removed all the leading whitespace from all the code sections. So read up about how to deal with this and it looks like the <pre> tag is supposed to help with this. However, it makes it look really ugly as it adds another box around the whole thing because of the <pre> tag.

    [cc lang="cpp"]
      print("hello world");

    Is there a way to tell WordPress that I don’t want the visual editor to reformat my text every time I open the visual editor? I searched the web and the WordPress forums, but have come up with nothing so far. This seems like a really big change as it makes formatting text very difficult now. I really liked my original workflow of switching to the text editor, pasting the code, then switching back.


Viewing 2 replies - 1 through 2 (of 2 total)
  • Andrew Nevins


    WCLDN 2018 Contributor | Volunteer support

    Like this or ?

    Switching editors to preview your work isn’t how WordPress intended editors to work. You’re meant to use the “Preview” button for that. This doesn’t however mean that your workflow is wrong, but that you need to look at plugins to overcome this.

    Thread Starter demolishun


    I was not using the Visual editor to preview. I was using the text editor to enter my text to prevent the visual editor from removing whitespace when I pasted the code. Now, however, WordPress removes whitespace from the beginning of lines upon opening a post in the visual editor. This has made my workflow different.

    I found a workable solution now. By using the “pre” with a css class I can enclose my code. Then to remove the outer box that would appear around the Code Colorer box I set the css to this:

      margin: 0 0 0;

    This has solved my issue and workflow problem. Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Visual Editor Removing Leading Whitespace’ is closed to new replies.