Posting source code in WordPress hosted blog

Hi there!

Two days after my last post, I noticed that the example code from that post had been removed 😦
This is really bad, and proves me a bad tester! Hope to improve on this soon, which should be important for becoming a good blogger!

So, I decided to write a post in WordPress about writing posts on WordPress, which present any kind of source code! Sounds funny at first, but it is very useful for developers, who want to use the free version of the WordPress hosted blog to present examples of code to their subscribers! Thanks to a post on stackoverflow (http://stackoverflow.com/questions/1273647/how-do-i-add-syntax-highlighting-to-a-wordpress-blog-hosted-on-wordpress-com), I reached a link on the WordPress support site that described, how an internal code highlighting and formatting plug-in can be used, which is also available for the hosted WordPress version as well.

The obvious reason why WordPress strip off the source code that is being included in any post, is for security. They are mostly trying to avoid running javascript code, which could cause problems to the whole WordPress platform, that holds all the hosted blogs.

So, to accomplish presenting and highlighting source code in your WordPress blog, you should wrap your code in the following tags:

[sourcecode language=”css”]
your code here
[/sourcecode]

For making use of more options that this plug-in offers, you should get the information presented here:
http://en.support.wordpress.com/code/posting-source-code/

Happy Blogging!

Advertisements

About sermojohn

Professional Software Engineer
This entry was posted in Technology, Tips and tagged , , , , , . Bookmark the permalink.

4 Responses to Posting source code in WordPress hosted blog

  1. jyothikarthik says:

    Amazing, I’ve been searching for such a thing! 🙂 🙂

    I’ll definitely try this up on my next blog post! 🙂

    THANKS!

  2. jyothikarthik says:

    Reblogged this on Me.Blog = LookDirections.Below and commented:
    Clever trick!

  3. ehmatthes says:

    You’re not necessarily a bad tester. I have found that sometimes wordpress allows something, and then you look at it later and it is different. I was trying to find a way to insert links into image captions. I looked at my blog through a proxy filter, and the link was there. I looked the next morning, and it was gone. I think some code makes it through initially, and then gets noticed after a little while.

    • sermojohn says:

      Thanks for sharing your experience here!

      I can’t see the reason why these operations, like post content parsing/checking should be run asynchronously! Anyway, most of the times there is a proper way to do what you want to do, but its described in the WordPress documentation, which unfortunately does not come up in the first pages of search engines!

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