Abdus Sattar Bhuiyan
Abdus Sattar Bhuiyan

Reputation: 3074

How to keep html as html in wordpress?

I am using codeMirror to add TryIt Editor as like w3school. The following is working fine:

   <form>
       <textarea id="code" name="code">
       HTML CODE
       </textarea>
   </form>

But it is not working when I try to replace HTML CODE by the actual content as follows:

 <form>
       <textarea id="code" name="code">
        <?php the_content(); ?>
       </textarea>
 </form>

I find out the actual reason behind this problem. When I save post in text mode(as following image) all html looks okay. code editor with complete html page including head and body tags

But when I change text mode to visual mode and back to text mode I can see the following: code editor with only the content that was inside the body

I also try to wrap all the html with <pre> </pre> but no luck. Any idea?

Upvotes: 0

Views: 161

Answers (1)

Riccardo Mel
Riccardo Mel

Reputation: 161

Note issue of tinyMCE on WP.

You can check using this plugin: https://wordpress.org/plugins/preserved-html-editor-markup/

But if you want a preatty clean solution you can use SHORTCODE to render your HTML structure inside the post safely.

SHORTCODE DOCS: https://codex.wordpress.org/Shortcode_API

or see this guide (in italian lang but you can translate it).

https://www.targetweb.it/come-creare-shortcode-wordpress-la-guida-completa/

Upvotes: 1

Related Questions