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?
]]>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.
]]>Point is, that rearranging a page including the type of display element is very easy in raw HTML.
]]>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.
]]>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.
]]>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.
]]>