Posting Source Code on WordPress

Formatting code snippets for display in a blog post can easily become a tiresome battle between you and the WordPress WYSIWYG. I spent a fair amount of effort modifying the CSS for this blog in the hopes of creating a nice looking, custom box for the code. But just when I thought I had something solid, it would only take a simple switch between WordPress’s WYSIWYG and HTML editors to smash my dreams into shards of frustration.

I was about to start rummaging through tutorials on how to make a WordPress plugin, but decided to make a last minute search for existing solutions. Much to my surprise, I found that there is actually a source code box that is built-in! Now I feel pretty silly for all of my CSS shennanigans. Here’s a link to the discussion of this WordPress feature:

http://faq.wordpress.com/2007/09/03/how-do-i-post-source-code/

The great thing about this is that the source code for the feature is open source, and might come in handy if I decide to get ambitious enough for a custom plugin for the code snippet box. For now, I’m pretty satisfied with the look of the built-in feature and plan on revisiting my previous posts to fix them up.

As a final tip for posting code, to have the WordPress WYSIWYG only use single spacing for a newline, press Shift + Enter. 

Tags: ,

One Response to “Posting Source Code on WordPress”

  1. moffdub Says:

    Thanks for the tip! You enabled me to complete my latest post. I too was searching around for online formatters, contemplating using PasteBin, or trying to develop a simple macro in my text editor.

Leave a Reply