Posting Source Code
Here at Automattic we’re allllll about sharing source code. We’re easy, we give it away.
Tragically, though, using WordPress.com it is really, really hard to post source code. You have to know about HTML encoding, pre and code tags, and if you want any slick highlighting you have to convert it before you post it. You have to jump through all sorts of hoops.
Isn’t this much cooler?
$features = file_get_contents( 'http://wordpress.com/features/' ); preg_match_all( '|(.*?)
|is’, $features, $why_wp_rocks ); foreach ( $why_wp_rocks[1] as $slick_feature ) $hotness[] = $slick_feature; var_dump( $hotness );
If you want to know how to drop that science check out this FAQ entry, it’s as easy as a blog post on a Sunday. Like , we realize this feature will probably not appeal to many people, but if you’re the type that writes about programming your blogging life should be easier now.
Here’s another editing tip: if you press Shift + Enter it gives you a single line break instead of a double one.
Happy Labor Day!

September 3rd, 2007 at 6:49 am
I’ll try this one.
September 3rd, 2007 at 7:01 am
Looks like you folks labored this Labor Day weekend. I don’t do or write about programming, but I’m s-l-o-w-l-y learning about code just being here. Thanks for the links. We like you!
September 3rd, 2007 at 7:09 am
Cool feature! Nice job!
September 3rd, 2007 at 7:11 am
Great stuff! Thanks.
September 3rd, 2007 at 7:21 am
Thanks for this great feature! The thing most unpeasant about using blockquotes / code tags was that two minus-es (used as command line switches for example) got converted into a single dash. I haven’t checked yet, but I hope this is fixed with [sourcecode].
September 3rd, 2007 at 7:30 am
this is nice
September 3rd, 2007 at 7:49 am
It’s geek-o-licious.
What, no AJAX?
The scientifically impossible I do right away
The spiritually miraculous takes a bit longer
September 3rd, 2007 at 7:51 am
Ah displays very neatly, nice Matt, very nice =) Though, it’s in my opinion that I do not like the horizontal bar. I also love the header options *thumbs up*
September 3rd, 2007 at 7:52 am
Nice!
I really love you guys.
Every little thing you do makes me so happy, I know it’s silly.
Thanks.
September 3rd, 2007 at 7:57 am
cooooool I would love to try it
and yea .. the editing tip… is something that I’ve been waiting for
thanks
September 3rd, 2007 at 8:00 am
Exactly what I was looking for. You’re a star. Thanks.
September 3rd, 2007 at 8:05 am
Now that is cool, I might actually post some code now!!
September 3rd, 2007 at 8:07 am
Sourc-ey!! Ooops…I meant Saucy!!!!
September 3rd, 2007 at 8:14 am
Not a bad feature!! Should be handy by times… Thanks!
Erm, … but why isn’t the ‘code’ button visible in wysiwig mode? Why do we still have to switch to the ‘code’ mode? Why not having the botton in both modes?
September 3rd, 2007 at 8:51 am
Good one
Cheers Matt!
September 3rd, 2007 at 8:55 am
very useful…
I said this problem in furums yesterday and now you fix it. thanx
September 3rd, 2007 at 8:57 am
Thanks for the editing tip.
I always wondered how to get a single line break.
Thanks guys.
September 3rd, 2007 at 8:58 am
wow! this is great!!! i’ll use this when I want to share my codes to others! Thanks WordPress!
September 3rd, 2007 at 9:05 am
Oh, you champion! I need single line breaks for some examples I give of other languages, for which I use three lines; the example, the morpheme gloss and the free translation. This saves me going into the code and manually removing the paragraph HTML tags. If only WLW had a way of doing that as well, I’d be all set.
September 3rd, 2007 at 9:17 am
Thanks a lot. This feature is definitely useful for me.
September 3rd, 2007 at 9:22 am
very cool and useful!
September 3rd, 2007 at 9:25 am
Looks nice, just a pity with the bottom scrollbar if you use larger than the default font
September 3rd, 2007 at 9:36 am
I already tried latex and it was fun…thanks for sharing this code
September 3rd, 2007 at 9:40 am
Thanks, sometime I used to post html code, that I had in text file located elsewhere. This will be useful.
September 3rd, 2007 at 10:08 am
Another great update, eh?
Thanks a lot.
September 3rd, 2007 at 10:30 am
YES!
At last. I please you for this feature. Thanks!
September 3rd, 2007 at 10:46 am
I dont know much about source code but I learn! Thanks
September 3rd, 2007 at 10:48 am
Wow, looks really nice. Thanks!
September 3rd, 2007 at 11:01 am
Awesome! It’s a wonderful feature!!! Thanks guys!
September 3rd, 2007 at 11:02 am
simply wondarful. bless.
September 3rd, 2007 at 11:14 am
Shirt + Enter… YAY…!!
September 3rd, 2007 at 11:21 am
Guess I’m a little too young for programming but fluent in UBL - Universal Baby Language. Maybe you can add it - only very few keywords used there
.
Anyhow great.
September 3rd, 2007 at 11:22 am
I’m not one who’s going to be posing much code, but I’ve been wanting something that’ll do a single line break for ages. Thank you! You’ve now ended quite a bit of frustration
September 3rd, 2007 at 11:29 am
thanks a lot! that’s really helpful!
September 3rd, 2007 at 11:37 am
wow. thanks great matt!!
September 3rd, 2007 at 12:18 pm
[...] مت بزرگ اعلام كرد كه آرزويم برآورده شد! اكنون شما ميتوانيد برای موارد [...]
September 3rd, 2007 at 12:22 pm
U guys rock!!!!
As u said, it wont appeal many…but I am glad it makes my blogging life easy.
Keep rolling.
Cheerz
Sridhar
September 3rd, 2007 at 12:27 pm
Ummm, not for me…wysiwyg works just fine.Thx!
September 3rd, 2007 at 12:42 pm
Hey Matt,
I’ve ran into the same problem on wordpress.
Try “:TOhtml” in vim. It exports syntax highlighting for whatever file you are editing like C, PHP, Python, bash, etc.
You may have to tweak the html a bit afterwards, but it produces great results. See: http://electronjunkie.wordpress.com/2007/06/30/sigma-delta-modulation-primer-part-ii/ for an example.
-ej
September 3rd, 2007 at 12:45 pm
Go WP!
Shift + Enter also opens a link in a new window. :p
Happy Labor Day!
September 3rd, 2007 at 1:12 pm
I have no reason to use this feature, but I appreciate how much ya’ll have worked to make WordPress the greatest!
Matt, how’d you get to be so cool?
September 3rd, 2007 at 1:31 pm
Yep, much cooler. As someone who does blog about programming occasionally this will be helpful, thanks.
September 3rd, 2007 at 1:48 pm
Woo-hoo! I was having HTML scratches to write codes before. Thanks — as usual!
September 3rd, 2007 at 2:13 pm
That shift+enter thing is the real winner here.
September 3rd, 2007 at 2:36 pm
good
September 3rd, 2007 at 2:37 pm
It’s a good idea, but it’s pathetic that it doesn’t support Perl syntax highlighting yet considering the twelve languages there.
September 3rd, 2007 at 2:38 pm
If you’d like Perl support contribute it to the open source project linked in the FAQ and we can add it.
September 3rd, 2007 at 2:40 pm
Oh this is great! This is really going to make life easier for me on my blog.
September 3rd, 2007 at 2:49 pm
Very nice indeed. Been looking for this for quite a while. Thanks.
September 3rd, 2007 at 3:06 pm
Cool!
September 3rd, 2007 at 3:12 pm
very awesome.
shift+enter is a great trick, i’m surprised more people don’t know about it.
September 3rd, 2007 at 3:35 pm
Thanks for this, really is need. I know XHTML and bought th Custom CSS upgrade… but never could highlight the language sintax by hand.
September 3rd, 2007 at 3:38 pm
“Here’s another editing tip: if you press Shift + Enter it gives you a single line break”
Now that makes me very happy! No more writing haiku in notepad first
September 3rd, 2007 at 3:55 pm
Hello Matt (from greece) !!!
Thanks for the tips and please do not stop sharing with us
September 3rd, 2007 at 4:08 pm
[...] read more | digg story [...]
September 3rd, 2007 at 4:11 pm
Seems perfect!
And is just what I need!
September 3rd, 2007 at 4:17 pm
Sweet. I like this. Thanks Matt.
September 3rd, 2007 at 4:21 pm
Very impressive. Thank you guys!
September 3rd, 2007 at 4:42 pm
It always confuses me that labor day is a different day in the states, and I do not post source code all that often, but anyway: thanks, and happy labor day to you as well.
September 3rd, 2007 at 5:06 pm
Just in time, I was planning on posting up some source code today.
September 3rd, 2007 at 5:06 pm
You don’t support perl
September 3rd, 2007 at 5:16 pm
WordPress is truly the gift that keeps on giving. I should probably be embarrassed to have this much joy at a new feature. Thank you!
September 3rd, 2007 at 5:18 pm
Cool!
But I think it should be great if it could have “themes”, even if there were only 2: light (the actual) and dark.
This would be good for people, like me, whom use dark themes. The source code actually draws too much attention to itself.
September 3rd, 2007 at 5:28 pm
woo!
September 3rd, 2007 at 5:59 pm
I’ll use this.some day. very soon
probably…
September 3rd, 2007 at 5:59 pm
Woohoo — I’d even started up a self-hosted blog just so I could load plugins to do this (of course, I haven’t posted anything to it yet, just let the plain-text formatting suffice on here).
That’s too cool…
September 3rd, 2007 at 7:14 pm
[...] 9/2/2007: WordPress.com adds Source Code Support. My Related Posts: .NET, [...]
September 3rd, 2007 at 7:47 pm
Another wonderful feature! Thanks a bunch!
September 3rd, 2007 at 7:57 pm
It seems like HTML tags above body content level (head, body, meta, doctype, style, …) are stripped out of the posting, which renders this feature’s use for HTML somewhat limited. Fix plz kthx
September 3rd, 2007 at 8:01 pm
brilliance. sheer brilliance…
September 3rd, 2007 at 8:12 pm
Thank you!
September 3rd, 2007 at 9:08 pm
shift+enter = : )
Thanks muchly!
September 3rd, 2007 at 10:53 pm
This is really helpful, actually… despite the fact that I don’t write code.
Thanks for the tips.
September 4th, 2007 at 12:45 am
I’m going to boo in here, since I cannot understand for the life of Brian why it has to take you over a year to accommodate the large group of developers, of which you are part, to make blogging easy for us. I have craved for this feature for so long where other blogs automattically have this from the start. Now on to free CSS and paid ‘other stuff’.
September 4th, 2007 at 1:16 am
Holy cow! About the best update since, uhh…. when was your last post?
September 4th, 2007 at 2:19 am
[...] chức năng cho phép post source code trên WordPress đã có. Hãy xem hướng dẫn của Matt, tác [...]
September 4th, 2007 at 2:45 am
[...] info By SAKi Lovre Categories: Blog Via: WordPress.com Link: [...]
September 4th, 2007 at 4:12 am
Thanks for working away on labour day with the post.
September 4th, 2007 at 4:25 am
[...] 4th, 2007 The wonderful guys at WordPress have given a wraparound so that posting source code is easier; it can’t get any better than this. Look out these pages for more phase field codes! For now, [...]
September 4th, 2007 at 4:43 am
What a great feature! My blog doesn’t deal with programming, but this is a great tool for those blogs that do.
September 4th, 2007 at 4:50 am
Thanks for your reply. I had a look at the so-called “open source” project listed, and the javascript there is all crushed up by some kind of compressor so that it’s virtually unreadable. Do you have a reference to the uncrushed javascript or a simple way to uncompress it? Otherwise adding a Perl mode isn’t really a practical job.
September 4th, 2007 at 4:53 am
Oops, take that back, I found the uncompressed directory.
September 4th, 2007 at 6:56 am
cool.. i really needed it
September 4th, 2007 at 11:24 am
This is very cool.
It woud be nice if there was a way to have the pretty display but without colours, either for languages that it didn’t recognise or when I didn’t want to use syntax highlighting.
September 4th, 2007 at 12:24 pm
Outstanding! It looks great. Nice feature.
September 4th, 2007 at 12:41 pm
Very cool, it will come in handy! But even better than the source code is Shift + Enter! I’ve been dying for that some time now…
September 4th, 2007 at 1:24 pm
thanks
September 4th, 2007 at 3:16 pm
wh000t, god thank you for this (late, but now we have it *yeah*) feature.
I hated the “replace spaces with and never edit this post ever”-shit ;)
this feature rules! (especially for my development-blog ^^ )
regards
ShoX
p.s.: Shift+Enter …. Why I didn´t try this earlier?! *d0h*
September 4th, 2007 at 3:27 pm
It sould be posted long time ago. But thanks, one right step was made by wordpress.
Shift+Enter…… never been easier to write a “” : )
September 4th, 2007 at 3:42 pm
Will you add this to v2.3 please?
September 4th, 2007 at 3:57 pm
One warning, I tried using the XML tag to post some XAML.
DON’T!!! It butchered the XAML badly, stripped out half my tags. Fortunately I write all my posts in Word prior to putting in WordPress, so I was able to go back to the original.
If it works with some of the other languages though, it could make for an extremely nice experience for the blog reader, especially the ability to copy the code.
Arcane Code
September 4th, 2007 at 3:59 pm
Fantastic, it’ really make me do not want to leave from my laptop, event to rest room.
September 4th, 2007 at 4:21 pm
Thank you. YOu are really helping us.
September 4th, 2007 at 4:27 pm
Finally!!
thanks a lot for finally implementing this!!
Will this be on wp self-hosted version also? or do I need a plugin for that.
September 4th, 2007 at 5:00 pm
Cool!!!!
September 4th, 2007 at 5:09 pm
Thanks, this is a big step forward from wrangling pre and code tags. However (a), why no Perl (you’ve got Ruby and Python!), (b) no C++?, (c), which language is recommended as “most similar” to perl, to get the right syntax highlighting, and (d), thx for the Shift+Enter, but how about not throwing away my indentations?
September 4th, 2007 at 5:25 pm
Nice - but can you please add some generic source code type for languages not listed? I’m missing “shell” for example…
September 4th, 2007 at 6:45 pm
Thanks for that last tip
it will be useful!
September 4th, 2007 at 8:17 pm
[...] 5th, 2007 Терь тут есть подсветка синтаксиса, но сделана она [...]
September 4th, 2007 at 8:58 pm
That’ll be helpful. Thanks!
September 4th, 2007 at 9:12 pm
cool
September 5th, 2007 at 12:35 am
Kick butt feature!
September 5th, 2007 at 1:45 am
I know your guys try every possible ways to improve WP for this community. Many thanks for every improvements you have made.
September 5th, 2007 at 2:22 am
This is cool and I sure that this will appeal to many users.
September 5th, 2007 at 3:40 am
Thats insanely interesting.
September 5th, 2007 at 6:32 am
I tried… It’s work. Very usefull. Thanks!
September 5th, 2007 at 6:44 am
COOL!! I love this. Thanks a lot, man.
September 5th, 2007 at 7:20 am
Great. I dont get it
September 5th, 2007 at 7:38 am
[...] post. It’s also great timing that WordPress has put up a source code tag for easily integrating code into blog posts. I’ll try to put up these posts on a regular basis from now on. [...]
September 5th, 2007 at 8:30 am
wow, thanks a lot. this is exactly what I’ve been looking for.
been in trouble adding my coding tips back then (and got messed up with pre and code tags).
also thanks for the Shift + Enter tips.
September 5th, 2007 at 8:58 am
Cool
September 5th, 2007 at 9:29 am
cool lol
September 5th, 2007 at 10:06 am
Thanx Matt, thats cool man. . .
shift + enter , mean a lot to me
September 5th, 2007 at 11:24 am
This sounds interesting, I’m gonna give it a try.
September 5th, 2007 at 11:38 am
Thanks for the “Shift + Enter” Tip!!!!
September 5th, 2007 at 3:59 pm
[...] my request for being able to put music notation onto blogs. They’ve done it for and for source code, so it seems only reasonable that us musicians get a look in as [...]
September 5th, 2007 at 5:12 pm
Very, very cool. Thanks!
September 5th, 2007 at 5:20 pm
aww… this might be damn useful… tx a lot
September 5th, 2007 at 6:21 pm
thanks was looking for this for my new post
September 5th, 2007 at 8:19 pm
be nice when you get round to slashes (probably a criticism on xhtml and stripslashes).
September 5th, 2007 at 9:58 pm
How about an “Updated” entry widget? Also STICKIES!!!!
September 6th, 2007 at 9:18 am
Thank you again. Go ahead!
September 6th, 2007 at 10:10 am
[...] Thanks to Matt and Mark the code snippet now can look much [...]
October 5th, 2007 at 3:23 pm
[...] WordPress blogs - Source code syntax highlighting Filed under: Uncategorized — Sonny @ 11:23 pm Say goodbye to the code tag. WordPress.com blogs have a new shortcode to post source code with syntax highlighting. http://wordpress.com/blog/2007/09/03/posting-source-code/ [...]
January 1st, 2008 at 9:33 pm
[...] I wanted and after an hour or so of googling, I found that they’ve implemented a pretty sweet code formatting feature. To give this a whirl take a look at the code [...]
February 16th, 2008 at 4:45 pm
[...] della padrona di casa per fare il mio esordio qui su usare.wordpress.com traducendo l’odierno annuncio da parte del team di Worpdress.com su come fare a pubblicare dei blocchi di codice sorgente nel [...]
April 26th, 2008 at 8:03 pm
[...] to post some code for a problem I have experienced in MOSS (well, who hasn’t?!) In this post (thanks Matt) I saw that in version 2.5.1, it should be quite easy. By using the new shortcode [...]