5

I've got a WordPress blog on WordPress.com. When posting something I'm including some sample Java code in the <code tags, is there any way I can have this formatted better? Such as syntax highlighting and line numbers etc?

An example of what I have is here, even though I have the code tags it doesnt seem to make it any more readable than normal text

Am I limited in choices as I've gone for the free option?

3
  • I assume you mean wordpress.com as "the wordpress site".
    – hakre
    Sep 4, 2010 at 12:10
  • 1
    @hakre: There you go again with the improper casing of the trademarked term WordPress. I know you think it's a statement but it makes you (and the site) look sloppy. Sep 4, 2010 at 19:14
  • @MikeSchinkel: From what I see in the revision history, I never edited that answer.
    – hakre
    Feb 3, 2011 at 11:35

2 Answers 2

7

wordpress.com supports code syntax-highliting. You can read all about it here: http://en.support.wordpress.com/code/posting-source-code/

for your specific example use:

[sourcecode language="java"]
package com.jameselsey.domain;

import java.util.ArrayList;
import java.util.List;
import com.google.android.maps.GeoPoint;
import android.app.Application;

/**
* This is a global POJO that we attach data to which we
* want to use across the application
* @author James Elsey
*
*/
public class GlobalState extends Application
{
private String testMe;

public String getTestMe() {
return testMe;
}
public void setTestMe(String testMe) {
this.testMe = testMe;
}
}
[/sourcecode]
1
  • You can use "lang" instead of "language" if you're into the whole brevity thing.
    – Mr_Chimp
    Jun 15, 2011 at 13:45
5

Yes you can. It's [code] *your code here* [/code] and you can even hint the language: [code lang="php"]<?php echo 'test'; ?>[/code].

This is the method I prefer (quick to write). There seem to be other ways as the following resource explains: Support: Code » Posting Source Code (wordpress.com)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.