If one runs a blog and if it is associated with development, in case if the individual wishes to share code snippets on his blog, then displaying these codes in the blog is not a simple task. A raw code that is added into the posts, comments, or widgets is filtered by WordPress for security reasons.  Most often if the user uses a display code on his website then that user is asked about the Syntax Highlighter plugin.

Now let us see how the display code can be added easily on a WordPress Website using Plugin.

First install and activate the Plugin Syntax Highlighter Evolved.

1 Add Plugins ‹ Linux and Windows Shared Hosting Coupons – WHS — WordPress 2015-12-30 17-19-06

 

On activation, 

SCR1-Plugin9

one needs to visit,

Settings >>> Syntax Highlighter to configure the plugin settings.

SCR1-Plugin7

For most websites the basic plugin setting will work fine but one must assess all the setting and make the necessary change if required. Every option descriptions are detailed that explains its functions. Once the required selection is made then to store the setting, simply click on save changes.

To display code, the Syntax Highlighter makes use of simple shortcodes. One needs to wrap the required code in the shortcode for that specific language.

If the language is PHP then one needs to wrap the code like this:

[php]
< ?php echo “Hi How Are You”; ?>
[/php]

It will appear in the post like this:

SCR1-Plugin5

In case of CSS the code can be wrapped like this:

[css]
.entry-title {
font-family:”Verdana”, arial, sans-serif;
font-size:18px;
color:#272727;
}
[/css]

It will appear on the site this way:

SCR2-Plugin3

Syntax Highlighter will spontaneously highlight the code for the specific language. It will also handle the tab indent correctly and add line numbers. The user can easily copy and paste the code snippets from the WordPress website.

How to Display Code on Your WordPress Site without using Plugin

Most of the blogger those who do not run a development blog, do not often need to add code snippets in their post. Once in a blue moon if required the blog owner can add code by encoding the required code into HTML entities like the subsequent…

&gt;?php echo ” Hi How Are You”; ?&lt;

The issue with converting code into HTML entities is that it is tough to do it manually, but there are many tools that can be used Encode the code into HTML entities.

After converting the PHP, JavaScript code into HTML entities they can be pasted into the WordPress post. If additional styling is required, then wrap the code sandwiched between <code> and </code> tags.