Displaying code snippets in your WordPress/Blogger blog posts or even your website can be a difficult task, because, you’ve got to make the computer understand that the code you are putting in the document is just for displaying and should not be executed. There are several ways of doing this which are very popular today.
DISPLAYING CODE SNIPPETS BY CONVERTING THEM INTO HTML (MY RECOMMENDED WAY!):
The best way to display code snippets anywhere (be it on a blog post, on a webpage, or even in an email!) is to convert them into pretty-printed HTML (Hyper Text Markup Language) which will then be embeddable in any place that supports HTML.
The steps are simple.
I do not need to explain you how to do it as it just involves copying and pasting your code into a text box on HILITE.ME website, copy the output HTML code and put it wherever you want to display your code.
That’s right fellas! Simple as that.
You have the following options available on www.hilite.me:
- Language (you have to select the language in which your code is written so that the code’s indentation, highlighting, coloring, etc. is done appropriately)
- Style (you can select that style you want to apply to the code snippet you just pasted from among a vast variety of styles like colorful, autumn, tango, etc.)
- Line numbers (You can choose if you want to display line numbers with the code or not. Generally, using line numbers is recommended if your code is very long. The line number will not be selected while selecting the displayed code)
- CSS (if the above options weren’t enough, you can modify the styling of the displayed code yourself)
Here is an example of the code snippet being displayed in the post after being converted into HTML format:
I really hope you loved this method of displaying codes on your blog posts/websites. Do know that I myself use this method only instead of using other syntax highlighters. You can check out “How To Enable Gzip On Your Website Or Blog” post if you really want to check whether or not I use this method. Comment below if you know any other methods that you are using currently or will be using even after reading this post! Also, share this post with your webmaster and blogging friends if you want to make the internet a better place.