Posting source code in WordPress blogs

In my previous blog post, I published the source code of a bash shell script. I noticed that WordPress kept on messing around with the code (like replacing some of the double quotes), and at first I didn’t know how to solve this (I’m quite new to WordPress).

And then I found the following support article:

http://en.support.wordpress.com/code/posting-source-code/

So, basically, you need to wrap your source code into “sourcecode” blocks, using the HTML editor.

There are also some nice options, like setting the language, enabling highlighting or line wrapping etc.

This is an example with sourcecode language=”bash” as option:

#!bin/bash

# description: source code example

echo "hello world!"

exit 0

Matthias

One Response to Posting source code in WordPress blogs

  1. rodrigolira says:

    Reblogged this on Blog do Rodrigo Lira and commented:
    That is the way how I post source code in my blog

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: