I am trying to display some HTML code in my blog post. Is there any way to show that HTML code as an element of that post?
Leave a Reply
You must be logged in to post a comment.
I am trying to display some HTML code in my blog post. Is there any way to show that HTML code as an element of that post?
You must be logged in to post a comment.
You should go through the documentation about
Writing Code in Your Posts.
It’s a nice article on how to display code in post/page of WordPress.
Super easy, and that WordPress Codex page Ram Sharma shared has great material to follow.
Put all your code within the
<code></code>
element and simply make sure to escape every opening less than symbol “<” and greater than symbol “>” though you might find yourself escaping other things:Example:
<code>
<?php echo $var; ?>
</code>
But in place of the greater than & less than symbol I replaced them with the appropriate HTML character entities “& g t ;” & “& l t ;” no spaces.
Check out an example of writing code in your posts over at my Web Development & Design Blog, no plugin! Pure code!
Building off of Giancarlo Colfer’s answer, you can use the
<code></code>
tags along with the<pre></pre>
tags.Example:
Your code will be output exactly as entered.
Great answers so far, I just wanted to add a tip.
If you are blogging about code you have already written; use a text editor (I use Notepad++) with a built in find and replace (Ctrl+H) function.
As before, remove the spaces from the replace string.
Finally – remember to undo the find and replace and/or don’t click save.