Publishing Source Code to WordPress Using Windows Live Writer 2011   2 comments

My previous blog post “Publishing Code Snippets on My WordPress Blog” explained how I used a read-only textarea to publish source code. Alas, WordPress has started stripping out <textarea> tags when you publish to their site or edit existing posts. They explain that this is for security reasons at

The above WordPress article also references another article at which explains that they have a “sourcecode” “short code” available which can help with publishing source code blocks or code snippets. Unfortunately, that article is muddled in how it presents how to insert the short codes, and also it does not offer any help for Windows Live Writer 2011 users.

After experimenting a bit, I have discovered how to easily use the short codes from within Live Writer, in combination with the <PRE> tag, and what to expect when using it in this editor.

The basic way to include a code block is as follows. Note that the short code tags are enclosed in square brackets rather than angle brackets. Also you will have to type this code in HTML view.


Please note that when you go back to the Edit view in Live Writer, the above “sourcecode” lines will appear as text. Do not edit these out. When you publish, the WordPress site will accept these and will not display them, but will interpret them correctly and display your code with the fancy highlighting.

A second important note: when in the Edit view in Live Writer, you will see your snippits appearing as plain text, without the syntax coloring. Don’t try to correct this. Once you publish the post to WordPress, it will appear as expected, with the syntax highlighting, toolbar, etc.

Please note that you must also include the <PRE> tag because if you do not, WordPress will remove the line breaks and tabs from your snippets when you publish.

In my example, the language=”sql” parameter specifies which language I want syntax highlighting for, in my case, SQL. The wraplines=”false” parameter ensures that a horizontal scroll bar will appear if I have longer lines of code. This particular option was needed with my WordPress theme, but you may need to experiment with this. The gutter=”false” parameter prevents line numbering in the code block. The full explanation of these and other parameters is explained in greater detail at

Happy blogging!


Posted June 20, 2011 by Norm Enger in Microsoft SQL Server

2 responses to “Publishing Source Code to WordPress Using Windows Live Writer 2011

Subscribe to comments with RSS.

  1. Copy button disappeared a while ago. Do you know why?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: