Do you run a development related blog and want to share code snippets on your blog posts? By default, showing codes in your WordPress site is not easy. For security reasons WordPress filters out any raw code added into posts, widgets, or comments. We’re often asked about what syntax highlighter plugin do we use to display code on our website. In this article, we will show you how to easily display code on your WordPress site.

First you need to install and activate the Synatx Highlighter Evolved plugin. Upon activation, you need to visit Settings » Syntax Highlighter to configure the plugin settings.


The basic plugin settings should work for most websites. However, you should review all settings and make changes if necessary. Each option has detailed description to explain what it does. Once you are done, simply click on the save changes button to store your settings.

Syntax Highlighter evolved uses simple shortcodes to display code. For each language you need wrap your code in the shortcode for that language.

For PHP you would wrap your code like this:

[php] <?php
echo “Hello World”;

It will appear in your post like this:

1 <?php
2 echo "Hello World";
3 ?>

For CSS you will wrap your code like this:

[css] .entry-title {
font-family:”Open Sans”, arial, sans-serif;

It will appear on your site like this:

1 .entry-title {
2 font-family:"Open Sans", arial, sans-serif;
3 font-size:16px;
4 color:#272727;
5 }

Syntax Highlighter will automatically highlight the code for that particular language. It will also add line numbers and handle tab indent properly. Your users will be able to easily copy and paste code snippets from your WordPress site.

How to Display Code in WordPress Without Using Plugin

Many bloggers do not run a development blog, so they don’t need to add sample code snippets in their posts very often. For rare occasions, you can add code by encoding the code into HTML entities. Like this:

&gt;?php echo "Hello World"; ?&lt;

The problem with converting code into HTML entities is that it is difficult to do manually. You can use online tools like this one, to convert code into HTML entities.

By converting PHP, HTML, JavaScript code into HTML entities, you can paste them into your WordPress posts. For additional styling you can wrap code between <code> and </code> tags.

We hope this article helped you find the best syntax highlighter plugin for WordPress. You may also enjoy our article about 13 plugins and tips to improve WordPress admin area.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Content Source