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( 'https://wordpress.com/features/' );
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 WordPress.com 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 1.6M other subscribers

127 Comments

Comments are closed.

  1. Richmond

    I’ll try this one.

    Like

  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!

    Like

  3. Mr. Saturday

    Cool feature! Nice job!

    Like

  4. Davor

    Great stuff! Thanks.

    Like

  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 [sourcecode].

    Like

  6. Kunal

    this is nice 🙂

    Like

  7. ClapSo

    It’s geek-o-licious.

    What, no AJAX?

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

    Like

  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*

    Like

  9. d.

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

    Like

  10. dinsan

    cooooool I would love to try it 😉

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

    thanks

    Like

  11. johno

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

    Like

  12. Wiebo

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

    Like

  13. Chittaranjan

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

    Like

  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?

    Like

  15. kazik

    Good one 😀 Cheers Matt!

    Like

  16. علي جباري

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

    Like

  17. Luke Skywalker

    Thanks for the editing tip.

    I always wondered how to get a single line break.

    Thanks guys.

    Like

  18. rowjie

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

    Like

  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.

    Like

  20. anaamica

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

    Like

  21. jonny

    very cool and useful!

    Like

  22. leppie

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

    Like

  23. cK

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

    Like

  24. JV

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

    Like

  25. p4ndu_Y4m4to

    Another great update, eh?
    Thanks a lot. 😀

    Like

  26. soltys

    YES!

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

    Like

  27. navcity

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

    Like

  28. Mori

    Wow, looks really nice. Thanks!

    Like

  29. gioxx

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

    Like

  30. The Magic Cauldron

    simply wondarful. bless.

    Like

  31. circulating

    Shirt + Enter… YAY…!!

    Like

  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.

    Like

  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

    Like

  34. Simão Freitas

    thanks a lot! that’s really helpful!

    Like

  35. mhmazidi

    wow. thanks great matt!!

    Like

  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.

    Cheerz
    Sridhar

    Like

  38. axewielderx

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

    Like

  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: http://electronjunkie.wordpress.com/2007/06/30/sigma-delta-modulation-primer-part-ii/ for an example.

    -ej

    Like

  40. cronies

    Go WP!

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

    Happy Labor Day!

    Like

  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?

    Like

  42. tread

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

    Like

  43. sora9n

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

    Like

  44. Rattling the Kettle

    That shift+enter thing is the real winner here.

    Like

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

    good

    Like

  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.

    Like

  47. Matt

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

    Like

  48. Ben Warren

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

    Like

  49. C4RL05

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

    Like

  50. Guillermo

    Cool!

    Like

  51. sunburntkamel

    very awesome.

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

    Like

  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.

    Like

  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 🙂

    Like

  54. parafonos

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

    Like

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

    Seems perfect!
    And is just what I need!

    Like

  57. Brent

    Sweet. I like this. Thanks Matt.

    Like

  58. Carlos

    Very impressive. Thank you guys!

    Like

  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.

    Like

  60. engtech

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

    Like

  61. engtech

    You don’t support perl 😦

    Like

  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!

    Like

  63. Rafa Soares

    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.

    Like

  64. pdtnc

    woo! 🙂

    Like

  65. chanux

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

    Like

  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…

    Like

  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! 🙂

    Like

  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 😉

    Like

  70. abu ameerah

    brilliance. sheer brilliance…

    Like

  71. The Canadian Cinephile

    Thank you!

    Like

  72. Lyndon

    shift+enter = : )

    Thanks muchly!

    Like

  73. katiefellows

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

    Like

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

    Like

  75. Alex

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

    Like

  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.

    Like

  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.

    Like

  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.

    Like

  82. BKB

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

    Like

  83. harshaonline

    cool.. i really needed it

    Like

  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.

    Like

  85. Bill Dollins

    Outstanding! It looks great. Nice feature.

    Like

  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…

    Like

  87. Sakib Al Mahmud

    thanks

    Like

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

    regards
    ShoX

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

    Like

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

    Like

  90. Ryan B

    Will you add this to v2.3 please?

    Like

  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

    Like

  92. frankykurniawan2000

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

    Like

  93. Jef Menguin

    Thank you. YOu are really helping us.

    Like

  94. chakrit

    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.

    Like

  95. Mangiucugna

    Cool!!!!

    Like

  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?

    Like

  97. liquidat

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

    Like

  98. dorine

    Thanks for that last tip 😉 it will be useful!

    Like

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

    That’ll be helpful. Thanks!

    Like

Create your new blog or website for free

Get Started