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 &lt;iostream&gt;
int main()
{
   std::cout &lt;&lt; &quot;Ah, much better&quot; &lt;&lt; std::endl;
   return 0;
}

 

It is quite simple!

One thought on “How to Post Source Code on WordPress.com

Leave a Reply

Your email address will not be published. Required fields are marked *