2 Easy Steps to Add Source Code into Your Blog

WordPress is a great blogging software. I am very happy with it except that it does not have nice built-in support to include source code, which an absolutely needed feature for me.

Given the rich set of plug-ins WordPress has, I know there must be some plug-in there already. Today I spent a little time on research. After trying several plug-ins, I decided to use Google Syntax Highlighter for WordPress. You can check out how it looks like as follows.

Bothered by SLOW Web UI to manage vSphere? Want to manage ALL your VMware vCenters, AWS, Azure, Openstack, container behind a SINGLE pane of glass? Want to search, analyze, report, visualize VMs, hosts, networks, datastores, events as easily as Google the Web? Find out more about vSearch 3.0: the search engine for all your private and public clouds.

Thinking many other folks may be interested in having this in their blogs, I decide to share it. It’s also a reminder for me later on for adding source code.

The installation is pretty simple. First, click on the Plugins and then Add New. On the page, type in Google Syntax Highlighter for WordPress. You will get it as the first item in the result list. Just click on the install link at the end of the item. It’s pretty straight forward and I don’t need to repeat it here.

After you install it, you can see a little link “usage directions.” You can find much information and discussion there. Here is what I used for my post:

1. Add the following part with source code into the post editor HTML mode.

... Your Source COde ...

You can change the value of class to any others like cpp, css, xml, html, csharp, javascript, python, ruby, sql, etc. These are pretty much all I need. More can be found here.

2. Add the following part at the end of the HTML source.






It should be working after you save the page.

The trick part is the name attribute in part 1. Somehow after I saved it, I could not find it later. It might be caused by the switching of visual mode and HTML mode. In the end, I switched to HMTL mode and made sure the name attribute there for sure before I saved it. The highlighting doesn’t work if the name attribute is missing. So pay a little attention there.




This entry was posted in Software Development and tagged . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

3 Comments

  1. Posted March 7, 2010 at 2:38 am | Permalink

    You might want to take a look at SyntaxHighlighter Evolved, which you can find at http://www.viper007bond.com/wordpress-plugins/syntaxhighlighter/.
    Just requires a simple start- and end-tag.
    And it also supports PowerShell, which of course convinced me 😉

  2. Posted March 7, 2010 at 12:45 pm | Permalink

    Thanks Luc,

    It looks simpler. How is the rendering speed? I found Google Syntax Highlighter sometimes takes seconds to render.

    -Steve

  3. Posted March 23, 2010 at 2:24 am | Permalink

    Just tried the SyntaxHighligher Evolved. It’s easier to use. So I switched to it. Thanks LucD!

    Lesson learnt: don’t take for granted things with Google keyword. It might be better without Google. :-)

    Tip learnt: want quick adoption by people? It might be better with Google. :-)

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

  • NEED HELP?


    My company has created products like vSearch ("Super vCenter"), vijavaNG APIs, EAM APIs, ICE tool. We also help clients with virtualization and cloud computing on customized development, training. Should you, or someone you know, need these products and services, please feel free to contact me: steve __AT__ doublecloud.org.

    Me: Steve Jin, VMware vExpert who authored the VMware VI and vSphere SDK by Prentice Hall, and created the de factor open source vSphere Java API while working at VMware engineering. Companies like Cisco, EMC, NetApp, HP, Dell, VMware, are among the users of the API and other tools I developed for their products, internal IT orchestration, and test automation.