Posting Source Code

Here at Automattic we’re allllll about sharing source code. We’re easy, we give it away.

Tragically, though, using 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( '' );
preg_match_all( '|<h3>(.*?)</h3>|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 \LaTeX, 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!

Missing out on the latest developments? Enter your email below to receive future announcements direct to your inbox. An email confirmation will be sent before you will start receiving notifications - please check your spam folder if you don't receive this.

Join 16,558,671 other followers



Comments are closed.

  1. Richmond

    I’ll try this one.

  2. museditions

    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!

  3. Mr. Saturday

    Cool feature! Nice job!

  4. Davor

    Great stuff! Thanks.

  5. Constantin

    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 .

  6. Kunal

    this is nice :)

  7. ClapSo

    It’s geek-o-licious.

    What, no AJAX?

    The scientifically impossible I do right away
    The spiritually miraculous takes a bit longer

  8. Xeos Celeres

    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*

  9. d.

    Nice! :)
    I really love you guys.
    Every little thing you do makes me so happy, I know it’s silly.

  10. dinsan

    cooooool I would love to try it ;)

    and yea .. the editing tip… is something that I’ve been waiting for :D


  11. johno

    Exactly what I was looking for. You’re a star. Thanks.

  12. Wiebo

    Now that is cool, I might actually post some code now!!

  13. Chittaranjan

    Sourc-ey!! Ooops…I meant Saucy!!!!

  14. Holger

    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?

  15. kazik

    Good one :D Cheers Matt!

  16. علي جباري

    very useful…
    I said this problem in furums yesterday and now you fix it. thanx

  17. Luke Skywalker

    Thanks for the editing tip.

    I always wondered how to get a single line break.

    Thanks guys.

  18. rowjie

    wow! this is great!!! i’ll use this when I want to share my codes to others! Thanks WordPress!

  19. Jangari

    Here’s another editing tip: if you press Shift + Enter it gives you a single line break instead of a double one.

    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.

  20. anaamica

    Thanks a lot. This feature is definitely useful for me.

  21. jonny

    very cool and useful!

  22. leppie

    Looks nice, just a pity with the bottom scrollbar if you use larger than the default font :(

  23. cK

    I already tried latex and it was fun…thanks for sharing this code :D

  24. JV

    Thanks, sometime I used to post html code, that I had in text file located elsewhere. This will be useful.

  25. p4ndu_Y4m4to

    Another great update, eh?
    Thanks a lot. :D

  26. soltys


    At last. I please you for this feature. Thanks!

  27. navcity

    I dont know much about source code but I learn! Thanks

  28. Mori

    Wow, looks really nice. Thanks!

  29. gioxx

    Awesome! It’s a wonderful feature!!! Thanks guys!

  30. The Magic Cauldron

    simply wondarful. bless.

  31. circulating

    Shirt + Enter… YAY…!!

  32. kexi

    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.

  33. Mildew

    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

  34. Simão Freitas

    thanks a lot! that’s really helpful!

  35. mhmazidi

    wow. thanks great matt!!

  36. Pingback: انتشار سورس كد در وردپرس « مزيدی
  37. srinix

    U guys rock!!!!

    As u said, it wont appeal many…but I am glad it makes my blogging life easy.

    Keep rolling.


  38. axewielderx

    Ummm, not for me…wysiwyg works just fine.Thx!

  39. electronjunkie

    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: for an example.


  40. cronies

    Go WP!

    Shift + Enter also opens a link in a new window. :p

    Happy Labor Day!

  41. Sherri

    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?

  42. tread

    Yep, much cooler. As someone who does blog about programming occasionally this will be helpful, thanks.

  43. sora9n

    Woo-hoo! I was having HTML scratches to write codes before. Thanks — as usual! :D

  44. Rattling the Kettle

    That shift+enter thing is the real winner here.

  45. آناهیتا دانشور


  46. BKB

    It’s a good idea, but it’s pathetic that it doesn’t support Perl syntax highlighting yet considering the twelve languages there.

  47. Matt

    If you’d like Perl support contribute it to the open source project linked in the FAQ and we can add it.

  48. Ben Warren

    Oh this is great! This is really going to make life easier for me on my blog.

  49. C4RL05

    Very nice indeed. Been looking for this for quite a while. Thanks.

  50. Guillermo


  51. sunburntkamel

    very awesome.

    shift+enter is a great trick, i’m surprised more people don’t know about it.

  52. Javier Aroche

    Thanks for this, really is need. I know XHTML and bought th Custom CSS upgrade… but never could highlight the language sintax by hand.

  53. Ray

    “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 :-)

  54. parafonos

    Hello Matt (from greece) !!!
    Thanks for the tips and please do not stop sharing with us ;)

  55. Pingback: Finally Shortcodes on « Nishu’s Apocalypse
  56. Γιώργος Μαργαρίτης

    Seems perfect!
    And is just what I need!

  57. Brent

    Sweet. I like this. Thanks Matt.

  58. Carlos

    Very impressive. Thank you guys!

  59. sungame

    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.

  60. engtech

    Just in time, I was planning on posting up some source code today. :)

  61. engtech

    You don’t support perl :(

  62. Martin Poulter

    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!

  63. Rafa Soares


    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.

  64. pdtnc

    woo! :)

  65. chanux

    I’ll use this.some day. very soon :) probably…

  66. mcory1

    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…

  67. Pingback: How to Post Code From Visual Studio to Your Blog « Jim 2.0’s Blog
  68. rod.

    Another wonderful feature! Thanks a bunch! :-)

  69. elpres

    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 ;)

  70. abu ameerah

    brilliance. sheer brilliance…

  71. The Canadian Cinephile

    Thank you!

  72. Lyndon

    shift+enter = : )

    Thanks muchly!

  73. katiefellows

    This is really helpful, actually… despite the fact that I don’t write code.
    Thanks for the tips.

  74. michiel

    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’.

  75. Alex

    Holy cow! About the best update since, uhh…. when was your last post?

  76. Pingback: Posting source code trên WordPress « Khi công việc yêu cầu phải học Java :-)
  77. Pingback: 在 Wordpress 中張貼 source code « なんでも
  78. cyclepromo

    Thanks for working away on labour day with the post.

  79. Pingback: Code: Circular hole under uniaxial stress « Materials, Science of
  80. Darmok

    What a great feature! My blog doesn’t deal with programming, but this is a great tool for those blogs that do.

  81. BKB

    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.

  82. BKB

    Oops, take that back, I found the uncompressed directory.

  83. harshaonline

    cool.. i really needed it

  84. drj11

    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.

  85. Bill Dollins

    Outstanding! It looks great. Nice feature.

  86. Brian

    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…

  87. Sakib Al Mahmud


  88. ShoX

    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 ^^ )


    p.s.: Shift+Enter …. Why I didn´t try this earlier?! *d0h* :D

  89. myshe

    It sould be posted long time ago. But thanks, one right step was made by wordpress.
    Shift+Enter…… never been easier to write a “” : )

  90. Ryan B

    Will you add this to v2.3 please?

  91. arcanecode

    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

  92. frankykurniawan2000

    Fantastic, it’ really make me do not want to leave from my laptop, event to rest room.

  93. Jef Menguin

    Thank you. YOu are really helping us.

  94. chakrit


    thanks a lot for finally implementing this!!

    Will this be on wp self-hosted version also? or do I need a plugin for that.

  95. Mangiucugna


  96. RubeRad

    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?

  97. liquidat

    Nice – but can you please add some generic source code type for languages not listed? I’m missing “shell” for example…

  98. dorine

    Thanks for that last tip ;) it will be useful!

  99. Pingback: Source « LG.BALUKATION’s WebBlog
  100. Lady

    That’ll be helpful. Thanks!


Get every new post delivered to your Inbox.

Join 16,558,671 other followers

%d bloggers like this: