Posts tagged: blogging tips

2 Easy Steps to Add Source Code into Your Blog

By Steve Jin, March 6, 2010

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.

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.




Author: Steve Jin is the author of VMware VI and vSphere SDK (Prentice Hall), creator of VMware vSphere Java API. For future articles, please subscribe to RSS or Email, and follow on Twitter.

Page 1 of 11

OfficeFolders theme by Themocracy