How to Display Code in WordPress Posts

One of the most common problem that new WordPress users comes across is displaying code in posts. The problem occurs when a user tries to share a code snippet into their posts. By default WordPress filters out the code and it becomes impossible to read. In this article, I will show how to display code in WordPress posts.

Using HTML Entities to Display Code in WordPress Posts

HTML entities are special code that is parsed by browsers to display the character associated with that particular entity. For example:

&amp; becomes &

&lt; becomes <

&gt; becomes >

Using HTML entities you can display code inside your WordPress posts.

&lt;div class="awesome"&gt; will be displayed in browser like this:

<div class="awesome">

This method is particularly useful if you just want to display a couple of lines of code. However, this method can be difficult to apply manually for multiple lines of code.

To solve this problem you can use an online HTML Entities encoder, like this one. Simply put the code you want to convert and hit the encode button. It will convert your code into HTML entities and you can safely paste that code inside <code></code> tag.

Using Plugin To Display Code in WordPress Posts

If you frequently share code snippets in your posts, then the above mentioned methods are not going to work for you. First thing you need to do is install and activate the SyntaxHighlighter Evolved plugin. It will save you from the hassle of converting code into HTML entities. Not only that it will highlight the code to display it in a much more readable format.

It works out of the box, all you need to do is wrap your content around specific language tags. For example, if you are sharing a code that is mainly in PHP, then you would wrap your code like this:

Thanks for your valuable posting.I have collect more than information from your website. It is really wonderful blog. please added more than tips. i’m working in Erp Software in india.Here providing very low price and Quality ERP,Cloud ERP, CMS , responsive webdesign and ERP. you have any more than information kindly make me call this number 044-42127512 or send your mail info@excelanto.com….