How to blog code at wordpress.com [closed]
Asked Answered
M

6

72

got a new blog at wordpress few days ago (http://ghads.wordpress.com) and I want to post some code snippets now or then. Is there anyway to make it look like code without paying for extra plugins?

Meehan answered 17/9, 2008 at 9:9 Comment(1)
what plugin did you use and theme for your blog, please share it if you canDaiquiri
H
116

See here: http://en.support.wordpress.com/code/posting-source-code/

Wrap your code in these tags: [sourcecode language='css'] .. [/sourcecode]

(or shorter [code lang='css'] .. [/code] )

Note that Visual Editor doesn't interpret the tags, you need to click Preview to see how it works.

Available language codes:

  • actionscript3
  • bash
  • clojure
  • coldfusion
  • cpp
  • csharp
  • css
  • delphi
  • erlang
  • fsharp
  • diff
  • groovy
  • html
  • javascript
  • java
  • javafx
  • matlab (keywords only)
  • objc
  • perl
  • php
  • text
  • powershell
  • python
  • r
  • ruby
  • scala
  • sql
  • vb
  • xml
Heracliteanism answered 17/9, 2008 at 9:11 Comment(9)
This page shows all the supported languages: en.support.wordpress.com/code/posting-source-codeHeliocentric
Doesn't work for me for some reason. I see the tags in the preview as if they were ordinary text.Graf
And no haskell... hilariousDestroy
@Graf why? I used it and the output is this: gsamaras.wordpress.com/code/quicksort-cHunsinger
Didn't work for me either: There is just large blank whitespace where the code snippet should have renderedMargemargeaux
Do the code tags use [] or <>? Should that be placed in the Wordpress editor's 'Visual' or 'Text' view?Margemargeaux
Does this work only on wordpress.com, whereas wordpress.org might require a plugin?Margemargeaux
If you are hosting your own wordpress site then you need to install the plugin "SyntaxHighlighter Evolved" and use the tag [code] ... [/code]. This is explained at the bottom of en.support.wordpress.com/code/posting-source-code.Xerophagy
Download the plugin from : wordpress.org/plugins/syntaxhighlighter Then upload the downloaded zip file (syntaxhighlighter.zip) in your wordpress site "Plugins" section. Click on "Upload Plugin" button to upload.Callison
N
18

You can also use hilite.me. It doesn't require installation of plugins or JS/CSS files. It's also open-source and has an API.

Disclaimer: I'm the developer.

Nolitta answered 28/3, 2012 at 10:38 Comment(4)
I find this much better than using the buildin [code] markdown, which seems to interfere with my code snippets. Thanks.Crossgarnet
This is super legit. Works and is just code tooBargeman
This worked far better for me than the accepted answer.Sarson
Works fantastic. Thanks!Irbm
U
3

Crayon Syntax Highlighter is an excellent free plugin. I went with that one, but there are many others I came across that may serve the purpose:

Unstopped answered 7/3, 2015 at 10:14 Comment(2)
Example link is broken.Greenhead
Crayon Syntax Highlighter it's work for meEmmalineemmalyn
F
2

There's a <code> html element you can use. Otherwise you could try the Textile or Markdown syntaxes (I'm not sure if WordPress.com uses them). Try it out and use the preview function in WordPress to see when you get it right.

Farver answered 17/9, 2008 at 9:13 Comment(1)
XML code strings have to be escaped when using <code> html element: #5963137Margemargeaux
M
1

With my Wordpress.org installation, I couldn't get the Accepted Answer here to work (not sure if that's only expected to work with Wordpress.com?)...

I ended up using the SyntaxHighlighter plugin instead.

With that plugin, at first, your code will appear escaped in 'Preview Changes' view: It will appear correctly then after publishing. I think thereafter publishing it will then appear correctly in 'Preview Changes' (not 100% about that).

Margemargeaux answered 16/10, 2015 at 20:14 Comment(0)
C
0

If you are hosting your own wordpress blog opposed to on WP.com you can get this functionality by installing this plugin, since it is the same plugin that the WP.com code relies on.

http://wordpress.org/extend/plugins/google-syntax-highlighter/

Caphaitien answered 30/10, 2008 at 19:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.