Sharing code snippets in WordPress posts

As I’m working on a personnal programming project, I had to think about a way to easily share some code snippets on this WordPress blog.

I ended up installing SyntaxHighlighter Evolved, which is a WordPress plugin developped and maintained by Alex Mills.

In the following, I go through the main steps to install it and to start using it.

  • Click on “Add New” from the “Plugins” category in the left-side navigation bar:
  • And then on “Upload Plugin”:
  • Finally, select the archive you just downloaded ( syntaxhighlighter.zip ) and click on “Install Now”:
  • [Optional] You can also customize layout and settings that will be used to display your code snippets:

Now that SyntaxHighlighter Evolved is installed, a new bloc type is available to you when writting/editing a post:

As I write this post, version 3.5.0 of SyntaxHighlighter Evolved supports the following programming languages:

ActionScript
BASH / Shell
C#
C / C++
Clojure
ColdFusion
CSS
Delphi / Pascal
diff / patch
Erlang
F#
Groovy
HTML / XHTML / XML / XSLT
Java
JavaFX
JavaScript
LaTeX
MATLAB
Objective-C
Perl
PHP
Plain Text
PowerShell
Python
R
Ruby / Ruby on Rails
Scala
SQL
Visual Basic

Here are some rendering examples for some popular languages with my custom settings (RDark theme):

Java

public class HelloWorld {

    public static void main(String[] args) {
        // Prints "Hello, World" to the terminal window.
        System.out.println("Hello, World");
    }

}

Python

# This program prints Hello, world!

print('Hello, world!')

C

    #include <stdio.h>
    int main()
    {
       // printf() displays the string inside quotation
       printf("Hello, World!");
       return 0;
    }

C++

    #include <iostream>
    using namespace std;
    int main() 
    {
        cout << "Hello, World!";
        return 0;
    }

In the event you are not satisfied with that plugin, you may want to check other alternatives out to display code on your WordPress site.

Happy code rendering to all!

+Stay tuned for more posts and tutorials
-to come on Antoine's Blog!

Sources: