Archived topic
The tag "code" does not work
8 replies · Started by David on September 21, 2018
Hi team,
When I need write some code in a post the tag "code" close before the code.
In wordpress html/text editor, I write
<code>
<div>Hola mundo </div>
</code>
When I switch to the visual editor and go back to the html/txt editor:
<code></code>
<div>
Hola mundo
</div>
Hi there,
It is because <div> is a block element which 'cannot' sit inside an inline element such as <code>
What are you trying to achieve with the <div> ?
I want to publish an article with code snippets and include "div"
Aah ok, how many articles do you intend to add 'code' into?
Their are a few ways to go about it.
Several, I've seen some plugin but they do not work either.
Do you have any recommendations?
Although it hasn't been updated in quite a long time, I still use the Pastacode plugin as I have found it to be the easiest to use and has the nicest display of all the others I have tried.
https://wordpress.org/plugins/pastacode/
Cheers!
Lyle
Thanks Lyle,
David, within the Visual editor try just pasting in the HTML without the <code> tags. Then highlight the code block and hit the Code button. Doing it this way should escape the HTML first.
- Lyle, I'll try it, although it has not been updated for two years.
- David, IT WORKS!
Thanks to both of you :D
Awesome :) the TinyMCE can be a little fickle at times.
If you're gonna be doing complex codes that may need updating, and don't mind the extra request then embed a Gist or a Codepen. You can then update the code in a decent code editor :)