How to Post Source Code on WordPress.com

Since most of the posts in this blog are programming related, I need to post source code from time to time. I’ve been trying to find a way to post source code in wordpress.com such that it will be syntax highlighting and all the goodies.

I tried to use the “/code” tag in the wordpress editor, but it outputs in some awkward font.

codetag
/Code button will insert around the text. The font chosen by this theme is not legible.


#include
int main()
{
std::cout<<"You can't read me anyway"<<std::endl;
return 0;
}

Use the Sourcecode Tag

So after some googling, I finally found a support page in wordpress. Apparently all you have to do is to wrap your source code in

[sourcecode language=”???”] [/sourcecode]

Replace ??? with the language of your choice. For example, C++ will use “cpp”.  See the support page for the complete list.

#include <iostream>
int main()
{
   std::cout << "Ah, much better" << std::endl;
   return 0;
}

 

It is quite simple!

One comment

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 )

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