• Resolved chcw

    (@chcw)


    Hi,

    When using Classic Editor, I encounter some strange things, as below:

    1. The “text” tab seems not be the HTML source code. Sometimes when I input HTML entities, such as <br/> and ;nbsp;, then save, then these entities will disappear and replaced with line break or space. So, how to input HTML source directly?
    2. Sometimes, the editor will refuse my changes. For example, I input the following in text:
    &nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;

    then save it, then in the “Visual” tab, there will be ” – “. Then if I switch back to “Text” and then “Visual tab, the first two spaces will disappear and become “- “. Very strange.

    3. I input the following codes in “text” tab:

    <a class="btn" href="javascript:;" onclick="CopyCurrentPostURL();">Copy Link</a><div id="inlinemsg" style="color: red; display: inline-block;"></div>

    I use “inline-block” in hoping the message will appear as the same line as the previous <a> tag(a button). However, after saving, if I switch to “Visual” and then back to “text”, then the code will become:

    <a class="btn">Copy Link</a>
    <div id="inlinemsg" style="color: red; display: inline-block;">&nbsp;</div>

    Some attributes in the <a> tag are removed. And div tag has been moved to the new line. Why?

    4. Even if I input the following line in “text” and do not switch to “Visual” and back:

    <a class="btn" href="javascript:;" onclick="CopyCurrentPostURL();">Copy Link</a><div id="inlinemsg" style="color: red; display: inline-block;"></div>

    After publishing, the text is not changed. But the final HTML page will add <p></p> around the <a> tag, always making it to be in the different line as the inline message. Why?

    I make a test page at https://www.datanumen.com/blogs/zh-hans/test-button/ which shows the issue.

    • This topic was modified 1 year, 6 months ago by chcw.
    • This topic was modified 1 year, 6 months ago by chcw.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    You may find it hard to believe, but that’s “normal” behavior ?? Or at least it has been that way for many years. The text view is not like a code editor where you can put anything you like and it’ll be saved exactly as-is. When you switch to visual view, the text is run through a variety of filters like wpautop(), wp_kses() and others that manipulate the HTML to keep it “WordPressy”. I speculate it’s so the applied theme CSS will behave predictably, but IDK.

    I’m sure you’ll agree that it’s pretty annoying when you know what you want to do but the editor will not let you. While it’s possible to disable the filtering, doing so typically then causes display issues with other existing content. In particular, I recommend never placing JS code into the editor. It invariably gets corrupted at some point. If you’re after some particular layout requiring certain HTML that the editor will not allow, it’s best to let the editor have its way and manage layout with some custom CSS.

    If you absolutely need specific HTML or inline JS within post content, it should be inserted via a custom shortcode.

    Thread Starter chcw

    (@chcw)

    It’s really a shock to me. I have noticed these issues in the past. But they are too minor and I doubt these may be due to the theme I am using.

    Anyway, thank you very much for your explanation. I will make designs via CSS and shortcode.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Some strange things with Classic Editor’ is closed to new replies.