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.
#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!