Content Notice!

This post is really old, and no longer reflect my skill level, views or opinions, it is made available here for archival purposes (it was originally on my old WordPress blog).

Keep that in mind when you read the contents within.

Syntax Highlighting In WordPress

Here is a really quick and simple tip for anyone of the programmers out there using WordPress. Ever wondered how you get fancy code highlighting in your WordPress posts without using an external tool like tohtml, it's really quite simple actually, you just have to install a plugin! :D The one I have used and had the most experience with is the Crayon Syntax Highlighting plugin, It's got a few themes to chose from, as well as the ability to make your own custom theme.

Here is an example with some random PHP code that was in my laying in my text editor at the time of writing:

// TODO: broken, fix
public function login () {
    if (!$this->account_model->logged_in() ) {
        if (!null == $this->input->post("submit")) {
            if ($this->account_model->login_user(
                $this->input->post("username"),
                $this->input->post("password")
            )) {
                // Successfully logged in
            } else {
                // Login is wrong
                $data["errors"] = $_SESSION["errors"];
                $this->load->view("account/login", $data);
            }
        } else {
            $this->load->view("account/login");
        }
    } else {
        redirect("account");
    }
}

The reason Crayon is a great plugin is because of the vast amount of languages it supports, as well as the ability to customize the look and feel of it to a great extent, so you can make it fit with your current blog design.

How to install Crayon.

1. Login to your WordPress admin dashboard. 2. Hover over the "Plugins" in the right sidebar. 3. Select "Add new" from the menu that pops up 4. search for "Crayon Syntax Highlighter" 5. Click on "Install Now". 6. then wait for it to download and install, then you click on "Activate".

You will now have a menu option in your "Settings" menu, called "Crayon", this is where you will configure your theme and settings. I like the theme called Monokai, because it looks like Sublime Text's default color scheme, which I quite like, But there are plenty to chose from if you don't like any of the ones provided you can click on any theme and DUPLICATE it, select it and EDIT(You can't edit an existing theme for some reason).