Posting Code to Your WordPress.com Blog

I made my first blog post yesterday and oddly enough, my only hurdle was finding a clean way to post code. After some Google Fu I found the a few different methods.

The first was to post my code inside a <code> tag. The <code> tag serves the purpose of setting your code apart from your regular text and is also ‘CopyandPasteable’ (you like that word? I just made it up). Here is an example of some code using the tag.

$(document).ready(function ()
{
if (code === 13)
{
alert("Yuck, this looks like crap");
}
});

As you can see, this method leaves much to be desired. Thankfully, I came across a better method which makes code look nice and fancy. By using the (sourcecode language=”javascript”) tag  (replace parenthesis with [brackets]) we have the same benefits that the <code> tag gives us, but presented in a much cleaner way.

Check it out:

$(document).ready(function ()
    {
    if (code === 13)
       {
       alert("Ooh! Ahh!");
       }
    });

You can use this tag for most types of code you would like to post, including SQL, JavaScript (as seen above), html, VB, ruby, C# and XML. The full list can be found here.

Welp, that’s all for today. #Ben, out!

Advertisements

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