How to display C code in a blog post

This post shows how to insert C code into a blog post. When everything is working correctly, the C code should appear like this to someone reading the blog post:

// Flashing LED example for PIC18F4620
// Written by Ted Burke
// Last updated 10-4-2013


#include <xc.h>

int main()
	TRISD = 0b11111110;

		LATDbits.LATD0 = 1 - LATDbits.LATD0;

Here’s how the C code above looked when I inserted it into the post in the WordPress editor (click to enlarge):


Opening and closing “sourcecode” shortcodes have been included just before and just after the C code. When adding the opening “sourcecode” shortcode, you have the option of specifying the programming language, which will enable colour-coded syntax highlighting. Here, I’ve set the language to “cpp” which means C or C++.

Important: Please note that I switched to “Text” view (rather than “Visual” view) before inserting the code. I recommend not switching back to Visual view at all once you have inserted code in your post, because switching back and forth seems to cause parts of the code to become corrupted, especially the symbols “<” and “>” which appear frequently in C code (for example in include directives and boolean conditions).


  1. Posting Source Code – Support –
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s