0

When I write pages, I want to code my own HTML to accomplish the design that I get.

For that I use "Text" editor view instead of "Visual" editor. I do not switch between them and when publishing the code, unfortunately, for some reason it automatically adds <p></p> and <br> elements breaking the design.

Am I missing some checkbox to tick to avoid this?

Is there any other solution that start using a plugin like raw html ?

2 Answers 2

1

While this sounds strange behavior, it does sound like you are doing it wrong. The wordpress "text" editor is not an HTML editor and should not be a replacement for one. It is useful for fixing whatever can not be done with the visual editor, but no more.

If you need a specific design which is just impossible to even get close to achieve with the visual editor, you should just create a page template for it. (It is unlikely that a author which do not understand HTML will be able to maintain the changes you are trying to do now, so no flexibility will be actually lost)

5
  • Ok, so I have just understood wrong the use for the text editor. I thought it was legit to add there html code. Feb 1, 2018 at 14:45
  • Templates are a good solution if it's a large-scale reusable design. If instead you need varying combinations of divs and things, shortcodes may work better. It is not unreasonable or unusual to add HTML to the text editor.
    – WebElaine
    Feb 1, 2018 at 14:51
  • 2
    @kitimenpolku, it is totally legit, but it will go via various filter which might change it. This is part of why it is not called "html" any longer (used to be called like that in the past). If you do not need the ability of author to be able to change it, page template are a saner option as that way you can use "pure" html/php wherever you will need it. Feb 1, 2018 at 15:36
  • Im a developer but I have other tasks. Daily changes in the design stop me for doing other tasks. And design is subjective to viewers opinion. We all have one. Im looking for a compromise so marketing team can work "its own way" without interrupting me for small changes. Html and CSS there seems legit if I get rid of those <p>s Feb 2, 2018 at 7:17
  • @kitimenpolku You are not making anyone's live easier by forcing them to learn HTML and denying from them the ability to use the visual editor. If this is a page that is being frequently modified you should figure in what way is it being modified and let the users modify only that part. In your original question you are still going to be the only one that is able to modify that page. Anyway, if you need to disable wpaotup for only one page, page template in which you remove the filter for only that page is still the way to go. Feb 2, 2018 at 7:25
0

If other non-technical editors will be working on the site, it's probably a good idea to use something else, like shortcodes. Shortcodes can output specific HTML structures but are easier for non-techies to paste into an editor. WP automatically strips some HTML (it seems to particularly hate Schema) when put directly into the editor, but if you use a shortcode it'll output those just fine.

If you're the only user on the site, though, there are other things you can do to ensure WP isn't adding all those extra <p> and <br> tags. The first thing is to simply remove carriage returns. In many cases, this will solve the problem or get you close enough to be workable. In other cases, you may still be running into way too many extra tags being added. There is a filter called wpautop which is what's automatically adding all these tags. If you have a good use case - like if you're the only editor and you're comfortable always inserting your own <p> tags for all posts - you can disable this filter. You can also get more specific; for example, maybe you want to set up a CPT for this type of layout only, and you can disable the filter only on that CPT, so you're not spending time adding <p> </p> tags everywhere on all your content.

There are plugins to disable the filter, but if you can code, it's easy enough to add it to your own plugin or theme. You simply say

remove_filter('the_content', 'wpautop');

to remove it everywhere. This WPSE answer explains disabling it only for certain CPTs.

1
  • Snippets would be a fine solution BUT non-technical team would not have access to those. I prefer that they have access to Html so if they need small changes they can do those by themselves. I will check the carriage returns I have setup. Thanks. Feb 2, 2018 at 7:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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