Publish code in wordpress


Publish code in WordPress is a really simple task. Here are the steps

Step 1

Open a new Post. (or, you can also highlight code in comment)

Step 2

Select “Text” from Top-Right corner of the post editor
(discard this step in case for comment)

Step 3

Copy source from code editor to post editor and surrounding it with code tag. Things should look like picture below.

publish code

Now Publish post / comment.

Output will be


public class HelloWorld
{
    public static void main (String args[]) {
        
        System.out.println("Hello World");
    }
}

Available Language tag

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

Collapse Code

collapse=”true” or “false”
— If true, the code box will be collapsed when the page loads, requiring the visitor to click to expand it. Good for
large code posts. Default is false.


public class HelloWorld
{
    public static void main (String args[]) {
        
        System.out.println("Hello World");
    }
}

Line number starts from

firstline=”5″ [first line will starts from 5]
— Use this to change what number the line numbering starts at. It defaults to 1.


public class HelloWorld
{
    public static void main (String args[]) {
        
        System.out.println("Hello World");
    }
}

Whether to show the gutter

gutter=”true” or “false”
— If false, the line numbering on the left side will be hidden. Defaults to true.


public class HelloWorld
{
    public static void main (String args[]) {
        
        System.out.println("Hello World");
    }
}

Highlight a specific code line

highlight=”3,5″ [line 3 and 5 will be highlighted]
— You can list the line numbers you want to be highlighted. For example “4,7,19”.


public class HelloWorld
{
    public static void main (String args[]) {
        
        System.out.println("Hello World");
    }
}

Show HTML script

htmlscript=”true” or “false”
— If true, any HTML/XML in your code will be highlighted. This is useful when you are mixing code into HTML, such as PHP inside of HTML. Defaults to false and will only work with certain code languages.

Light version

light=”true” or “false”
— If true, the gutter (line numbering) and toolbar (see below) will be hidden. This is helpful when posting only one or two lines of code. Defaults to false.


public class HelloWorld
{
    public static void main (String args[]) {
        
        System.out.println("Hello World");
    }
}

Pad line numbers

padlinenumbers=”true” or “false” or “3” [padding will be 3 spaces]
— Allows you to control the line number padding. true will result in automatic padding, false will result in no padding, and entering a number will force a specific amount of padding.


public class HelloWorld
{
    public static void main (String args[]) {
        
        System.out.println("Hello World");
    }
}

Code Title

title=”title_string”
— Set a label for your code block. Can be useful when combined with the collapse parameter.


public class HelloWorld
{
    public static void main (String args[]) {
        
        System.out.println("Hello World");
    }
}

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

One thought on “Publish code in wordpress

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s