One of the problems developers face when they want to highlight source code in their articles is code formatting. In default WordPress installation, when you paste a code inside the article, you will lose colored syntaxes, proper formatting, lines get aligned the way you want to present your code and you will face many other issues.
One thing I learned when using a WordPress is that plugins can get quickly abandoned. If you are using a plugin to embed shortcodes inside the posts, you may soon stumble on a problem. Plugin may stop being supported. When this happens you run a risk being exposed to vulnerabilities or plugin may get broken with the latest WordPress release.
When that happens, instead of beautifully formatted code, you may see short-codes along with wrongly formatted code. This is the last thing you want to see as it will break user experience with your site.
Embed code snippets in your WordPress blog with a plugin
You can highlight source code by using a plugin or you can embed snippets. We will cover both ways.
Crayon Syntax Highlighter
In addition it has so many options for showing your code in WordPress that it’s simply one of the best code syntax highlighting plugins available. Currently it has been downloaded for more than 340.000 times from WordPress repository. This is a plugin that can’t just go away. You can rest assured that it will grow with you website popularity.
WordPress Rainbow Hilite
WordPress Rainbow Hilite is a very promising code highlighting plugins. It features user friendly TinyMCE integration. It has support for many languages, but you can also load your own via hooks. Even though it’s a new comer with 720 downloads it looks very promising.
SmartAss Highlighter is easy to use and simple plugin for making code pretty in WordPress. It will highlight code between <pre> and </pre>. It has a pretty extensive languages support. You can enabled it per post basis by using a [highlighter] shortcode. You can change a theme by modifying highlighter.css file.
Enlighter is quite an amazing plugin for showing your code on your WordPress site. It supports most common languages and it uses a EnlighterJS to offer a beautiful code appearance. It features several CSS based themes which can be easily customized by Theme customizer.
With theme customizer you can define your own colors, font styles, font size and really make code stand out. It can display code groups in tab-panes. What makes this plugin really great is code preview inside the editor.
It looks like the author really cares about his plugins. He added support for CDN usage and integrated CSS caching.
Mivhak Syntax Highlighter
Mivhak Syntax Highlighter is based on improved version Google Code Prettifier. If features simple settings panel where you can set up basic appearance and behaviour. It’s very light, at 90 kb if ads only 3 additional requests for script, style and skin. If features 7 different skins. Control panel is easy to use and it supports more than 40 different programming languages.
Imagine that you you start using a plugin and after a year, you discover that plugin is no longer maintained. You would have a big problem. SyntaxHighlighter Evolved is one of the most popular plugins for highlighting your code. It has been downloaded for more than 420.000 times. Perhaps the most interesting thing about this plugin is that Automattic, company behind WordPress is also involved in a plugin development. Plugin being no longer maintained is not an option here as it’s being used on WordPress.com as well.
It features a simple settings panel. It supports many languages and you can choose several themes for displaying your code.
Embed Code Snippets in your post without using a plugin
When searching for a code to modify Genesis functionality, I found many professional Genesis bloggers were not using a plugin. Instead they relied upon code snippets repository. And reason is pretty simple. If they share their code, it’s available on code repository where others can find it and thus, drive additional traffic on their website. What a great way to highlight source code. And you get additional traffic too.
Second reason is that code can be reused by others in a simple way. When other people reuse your code, they are very likely to link to you as original author. What a great spirit and traffic generator.
Github is one of the most popular services to share snippets. Because all gists are Git repositories, they can be forked and usable from Git. You can have unlimited Gists that can be created by the user. It’s plain simple to use, all you have to do is to paste the code and embed in your article. It’s one of the most popular services for Genesis developers / bloggers.
Snipplr is a social snippet repository. You can find many useful code snippets there. And by many, I mean really a lot of code. From WordPress, Ruby, CSS… You name it, you will find it. It’s a paradise for web developers. Just like on Github, you can paste your code which you can embed and share with the others.
Pastebin is said to be no.1 paste tool since year 2002. You can set highlighting, Paste expiration and Paste exposure (public or private). You can post anonymously or you can register for an account giving you modification rights. While the place was supposed to be used by programmers and web developers, you can find anything in their Pastes. From hacked Facebook accounts, Password lists to Lenovo SuperFish signed certificate. Yes, you will also find a code.
Depending on your niche, you can use a plugin or you can use code snippets from one of online services.
When you decide on a plugin, make sure that plugins will grow with your website, that features will be added and that it will follow latest WordPress development.
On the other hand, if you are looking for a functionality that is not available in any of the popular plugins, you may opt for a newcomer. Make sure that you support developer, either by a donation, or by motivating them by telling them how you like their plugin.
Know a plugin missing on a list? Please share in comments.