When writing a blog post,many of us write the code for a particular application directly in the post which get executed(mostly for HTML tags and PHP code), in return messing things up. For example while telling your visitors how to make text bold, you would use the <strong> tag but when publishing the post, this will get executed and making text somewhere it shouldn’t, bold. Down here, I’ll show you how to write any code for any language the proper way, that is one in which it won’t be executed but nonetheless your visitors will be able to copy and use the code without any manoeuvre.

Previously I used different techniques to write code in my post like putting a space inside the tag so that it isn’t considered a valid tag like < strong > but when people would copy the code, the space will be in there too and it wouldn’t work on their side. It’s when Lorelle gave me a post that I was enlightened into the proper way of writing code.
You would wrap the <code> tag around your code so as to dress it with the respective style to distinguish it from the rest of your text. Then the proper way is to turn your code into character entities like the following :
From :
<code><strong>example code</strong></code>
to
< ;code> ;< ;strong> ;example code< ;/strong>< ;/code> ;
This can be applied to any language while you’re posting code. Lorelle gave a list of different converters but I’ve found one called Postable which is quick,clean and easy to use.

You put the code there and click on the make it friendly button(scroll down the page if you’re not seeing it) which will then provide you the character entities of the code. You then paste that in your post surrounded by the <code> tag to style it. When publishing your post, the code will appear like it should but without getting executed nonetheless.

I would advise you to bookmark Postable and put a link near your comment form if many of your posts and comments deal with code so that people can turn the code into proper character entities ready to be published.
If you need any help or clarification, please leave a comment or contact me and I will be glad to help you
related reading
- WordPress.com Blog Bling: Signatures and Writing Code
- How blogging old are you?
- Hiding your image buttons for some sidebar goodness
- Quick shooting stats of your Wordpress blog
- how-to contact form for blogger
- Give visitors what they want
- how to keep the everlasting blogging love
- Could blogger beat wordpress?
Tags: 22 Comments
22 responses so far ↓
[…] The proper way to write code in your blog posts […]
thanks for the tip!

@ waz
thanks for enjoying it
[…] The proper way to write code in your blog posts […]
[…] The proper way to write code in your blog posts […]
[…] The proper way to write code in your blog posts […]
[…] The proper way to write code in your blog posts […]
[…] The proper way to write code in your blog posts […]
[…] to Write Code in Your WordPress Blog Posts: Blogosquare writes about the proper way to write code in your blog posts and features my tips with the character entity code conversions list to help you turn code into […]
[…] The proper way to write code in your blog posts […]
[…] The proper way to write code in your blog posts […]
[…] The proper way to write code in your blog posts: how to write code in posts so that the blog doesn’t break when displaying them. […]
[…] The proper way to write code in your blog posts […]
[…] The proper way to write code in your blog posts […]
Are You Wasting Money on Over-Priced Ebooks?
Have you bought any of those $97 ebooks lately? In the last few years, ebook authors have been selling garbage ebooks for about a hundred dollars and they’re riding the gravy train at your expense.
Most of them would be no more than 10 pages if you took out all the worthless filler.
A couple of months ago, I bought an ‘expert’ ebook about how to make lots of cash every month from AdSense. After reading nearly 200 pages, all he said is to make the AdSense ads look like they’re part of your website instead of looking like ads.
This author took a simple idea and expanded it’s explanation by a factor of twenty just to give the impression of value. Nobody would be happy paying his price to get a 5 or 10 page ebook.
There’s a new trend in ebooks - make them ’short and to the point’. Refreshingly short ebooks that give you the knowledge you seek without making you wade thru page after page of irrelevant ramblings. Prices so low that the $97 ebook gurus might have a heart attack!
You want cheap? How does $7 sound to you?
Browse thru this Monsterous Selection of $7 Ebooks
[…] The proper way to write code in your blog posts: how to write code in posts so that the blog doesn’t break when displaying them. […]
[…] The proper way to write code in your blog posts: how to write code in posts so that the blog doesn’t break when displaying them. […]
[…] The proper way to write code in your blog posts - is a tutorial which shows how to write any code for any language the proper way, that is one in which it won’t be executed but nonetheless your visitors will be able to copy and use the code without any manoeuvre. […]
[…] The proper way to write code in your blog posts […]
[…] The proper way to write code in your blog posts […]
[…] The proper way to write codes in your blog. […]
[…] The proper way to write code in your blog posts: how to write code in posts so that the blog doesn’t break when displaying them. […]