Publishing Code Snippets on My WordPress Blog   Leave a comment

UPDATE 6/20/2011: This technique will no longer work. I have described an alternate technique in my new post

Here is the technique I use in WordPress in order to post code to my new “The SQL Guy” blog site. This places the code into a read-only textarea. Note the opening and closing “<pre>” tags. These preserve the original line breaks and white space of the code snippet. These tags, and the code snippets between them, must be entered in HTML view. Note that I use LiveWriter 2011 to edit and publish my posts.

<textarea rows=”20″ cols=”70″ readonly>

***Insert code snippets here***


Here is what the box will look like:

***Insert code snippets here*** Code line 1 - not indented Code line 2 - tab indented Code line 3 - indented 4 spaces 

One reason I like to use the read-only textarea is that I can control the rows and cols parameters so my code section takes up a limited portion of the screen but is easily scrollable. The other reason is that a user can easily copy all the code in the textarea simply by clicking anywhere in the textarea box, then pressing the keyboard combination Ctrl + A (to select all text in the code snippet area) and then Ctrl + C (to copy the selected text to the clipboard). He can then paste it into his favorite editor by pressing Ctrl + V.


Posted November 14, 2010 by Norm Enger in Microsoft SQL Server

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: