• Resolved michaelmossey

    (@michaelmossey)


    I’m fairly new to wordpress, but I’m more familiar with coding directly in HTML.

    I’m used to editing pages and other code in a straightforward text file. I’m a bit frustrated with WordPress page builders, because it’s so difficult to make changes. Let’s say I lay out some text in different blocks. With a WordPress page builder I have to create a bunch of different blocks, edit the text in the them separately. Then I come up with a different layout I want to try, different widgets or whatever. If I were in a flat text file, I would just cut and paste things in a couple places and be done with it. But with a page builder, I pretty much have to start from scratch and manually create various blocks and widgets, copy in all the text again, etc. Very frustrating.

    So I’m trying to use the WordPress code editor to type in raw HTML. It almost works, but I’ve noticed two things. One is that it removes all <p> tags. The other is that it’s sensitive to line breaks. This makes it a bit difficult to copy and past HTML into the code editor, because normal HTML formatting will have line breaks all over the place.

    Is it possible to really use raw HTML, or change the behavior of the code editor so it doesn’t make line breaks significant?

    • This topic was modified 5 years, 10 months ago by michaelmossey.
Viewing 9 replies - 1 through 9 (of 9 total)
  • Are you using the Classic Editor plugin? It adds p tags.
    There might be other editor plugins that make raw editing easier, such as removing the wpautop filter. That’s what the block editor did, but then they mess with the p tags in a different way. But there is also wptexturize which changes quotes and other things to HTML entities.
    There’s a fine line between sanitizing the input and making it display properly once it’s output.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    Let’s say I lay out some text in different blocks. With a WordPress page builder I have to create a bunch of different blocks, edit the text in the them separately. Then I come up with a different layout I want to try, different widgets or whatever. If I were in a flat text file, I would just cut and paste things in a couple places and be done with it. But with a page builder, I pretty much have to start from scratch and manually create various blocks and widgets, copy in all the text again, etc. Very frustrating.

    You don’t need to recreate the blocks. They’re blocks. You can move them around and reposition them without changing them. Move them above or below other blocks. Reorder them as you see fit. That’s the advantage to blocks, you don’t need to copy and paste text over and over again.

    So I’m trying to use the WordPress code editor to type in raw HTML. It almost works, but I’ve noticed two things. One is that it removes all <p> tags. The other is that it’s sensitive to line breaks. This makes it a bit difficult to copy and past HTML into the code editor, because normal HTML formatting will have line breaks all over the place.

    Is it possible to really use raw HTML, or change the behavior of the code editor so it doesn’t make line breaks significant?

    That would depend on how you’re doing it. If you use a Custom HTML block, then you can put the HTML you like into it and it will leave that HTML alone. But I doubt you want to write your whole post in HTML, so you can use the Custom HTML block just for the pieces you want to be custom.

    The Code editor is pretty raw and it will leave your code alone, as long as you stay in the code editor. If you switch back to the block editor, then it will try to interpret your code as blocks. And anything not in a block is considered to be in a “Classic Block”. And yes, the Classic Block will remove your P tags, and the reason for this is that the WordPress legacy code kicks in and does the “autop” process on classic posts.

    WordPress didn’t use to save P tags in the database. Instead, it has a bit of code called “wpautop” which automatically changes plain text into HTML by adding those P tags around paragraphs.

    Now with blocks, the editor handles those. Paragraph blocks have their tags, and each block does its own thing. The HTML is saved in the database as is, P tags and all. So wpautop doesn’t kick in for blocks, but for non-blocks, for anything outside a block, the old ways still apply, so wpautop will auto add P tags to that content. Which means that if you put P tags into a “Classic Block” (which is really a non-block), then it has to remove them, because wpautop will just end up adding them back.

    Thread Starter michaelmossey

    (@michaelmossey)

    By “block” I didn’t mean Gutenberg blocks. I meant the things that are used by Page Builders in traditional WordPress visual editor plugins. I guess I don’t know what those are called, officially. “widgets?” And I didn’t mean that I’m just changing the order. I mean that I’m changing the type of widget/block/whatever and possibly redistributing the text among the blocks. This is a common “refactoring” of pages I do when I’m messing around with a bunch of draft versions of the page.

    Point is, that rearranging a page including the type of display element is very easy in raw HTML.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    Ah. In that case, it would help to know what page builder that you’re using, and to direct you to ask them about it. I can’t speak to any particular page builders, as I’ve never used them.

    Thread Starter michaelmossey

    (@michaelmossey)

    EDIT: accept my apologies for yelling in the original post (below). I didn’t see your mention of the custom HTML block when I first read your first reply. I was looking at everything else in your reply, but the real solution for me is the custom HTML block. It’s perfect.

    original post:

    DON’T send me to a page build forum. I DON’T WANT TO USE A PAGE BUILDER.

    I’m asking about entering raw HTML.

    By the way, who moved this thread to “Fixing WordPress”? This has nothing with fixing WordPress. I’m asking about the behavior of the code editor when entering raw HTML. The behavior is what it is. It’s not broken. But I would like to understand if there is a way to use the code editor to enter raw HTML without any post-processing.

    • This reply was modified 5 years, 10 months ago by michaelmossey.
    Thread Starter michaelmossey

    (@michaelmossey)

    I just realized you wrote about a custom HTML block. In fact, I do want to do my whole post in HTML. So that will solve my problem. I’ll see if I can get it to work.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    OKay, you’re throwing a lot of terms around, without referring to what exactly they mean. You say you don’t mean a block in the gutenberg editor, but then you also say “code editor” which has a specific meaning in that editor, and then you say that the Custom HTML block is a good fit… So yeah, I’m confused.

    Clarification seems needed. If you do actually just want a big blank empty box where you can put your HTML, then the built in Code Editor would be a good fit, *except* that if you’re not actually using blocks, then it will kill your P tags.

    There is a difference in how code is saved to the database between posts-with-blocks and posts-without-blocks. Posts that have no blocks in them are presumed to be the old style, and thus the P tags are removed, and then readded with wpautop. This is because old versions of the editor did not include P tags in the content saved to the database.

    Blocks have their own P tags. So if you have a block, it ignores that step. And if you really want to use the actual Code Editor and the big gray box, here’s a little trick:

    <!-- wp:html -->
    HTML CODE HERE
    <!-- /wp:html -->
    

    That’s how blocks get saved in the database. Do that in the code editor, and it will not touch your HTML code.

    Thread Starter michaelmossey

    (@michaelmossey)

    By code editor, I’m referring to what you get when you select “Code editor” from the drop down menu, the one you launch by clicking the three dots at the upper-right corner of the screen.

    The good news is that two solutions work for me (I’ve tested both): before your latest post, I found that the Custom HTML block worked. And now that you’ve suggested the code editor, I did the following.

    – in the visual editor, create a custom HTML block and type code into it
    – switch to code editor
    – voila! the <!– wp:html –> tags are present

    So I think this is resolved.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    Great! I’m glad you found a way forward. If you have any other questions, or decide that hey, blocks ain’t so bad, let us know. ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘using code editor – why no paragraph tages?’ is closed to new replies.