Nov 7 2008

How to Show Code Examples in Blog Posts


I plan on sharing quite a bit of example html and php code for web design on deindexed.com. I have used text boxes on a few posts so far. The problem of using <textarea></textarea> is that its aesthetically ugly. Here is a simple trick that should solve the problem of not being able to include code examples in your posts.

Simply use character codes for < . Paste your code into Notepad, Click on edit and then replace < with &lt; . The resulting code can now be placed in any post and your readers can see your example code.

How did Deindexed write the code to show the character code?
The trick? In the text box when writing this post I had to write &amp; for the ampersand, so the code I actually wrote in my post editor to show the previous example to you was &amp;amp;

Examples:

  • typing &lt;textarea>&lt;/textarea> into your post editor will show your visitors <textarea></teaxtarea>
  • to show you &lt;textarea>&lt;/textarea> I needed to actually type &amp;lt;textarea>&amp;lt;/textarea> in my text editor
    Any code you copy from this site using this technique should be pasted into Notepad and then copied again to be used. Notepad strips character codes and line breaks ect and makes the code clean, ready to use.

Random Posts

LEAVE A COMMENT

Subscribe Form

Subscribe to Blog