How to post source code on WordPress

The trick is to use the WordPress
[ sourcecode] tag, as documented at

Note: You have to enclose the [ sourcecode] shortcut tag in square – not pointy – brackets.
Here is a snippets of C code.

The default for wraplines is true, which causes long lines to be wrapped. That isn’t appropriate for Python, so specify wraplines=”false” when applied to python.

The default for collapse is false, which works for most people. But I code it explicitly, as a reminder that if I ever want to collapse a long code snippet, I can.

After trying out almost ten plugins, I find Crayon Syntax Highlighter is the best to highlight source code in wordpress posts. This plugin is so awesome that it supports almost all the languages out there. For more details on supported programming languages and international languages, check out its description page.

After installing and activating Crayon Syntax Highlighter following the guide on its plugin page, you will see a crayon button icon on the toolbar in Visual mode, or crayon button button on the toolbar in Text mode while editing a post.

One may either

  • click the icon/button and paste your code in the popup box.
  • select the code fragment and click the icon/button.

to insert the source code.

If you want to manually type in the tag, it is

The result looks like: