» syntax/code highlight

Update: Oct 13th, 2010

Q: How to insert code snippet?

A: Using syntax highlighter shortcode

example:
How do i do that?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
 <title>PHP Code Example</title>
</head>
<body>
 <h1>PHP Code Example</h1>

 <p><?php echo 'Hello World!'; ?></p>

 <p>This line is highlighted.</p>

 <div>
 This	is	an
 example	of	smart
 tabs.
 </div>

 <p><a href="http://wordpress.org/">WordPress</a></p>
</body>
</html>

In wordpress text editor put shortcode like this around the code

1

Shortcode Parameters

These are the parameters you can pass to the shortcode and what they do. For the booleans (i.e. on/off), pass true/1 or false/0.

  • lang or language — The language syntax to highlight with. You can alternately just use that as the tag, such as
    1

    Click here for a list of valid tags (under “aliases”).

  • autolinks — Toggle automatic URL linking.
  • classname — Add an additional CSS class to the code box.
  • collapse — Toggle collapsing the code box by default, requiring a click to expand it. Good for large code posts.
  • firstline — An interger specifying what number the first line should be (for the line numbering).
  • gutter — Toggle the left-side line numbering.
  • highlight — A comma-sperated list of line numbers to highlight.
  • htmlscript — Toggle highlighting any extra HTML/XML. Good for when you’re mixing HTML/XML with another language, such as having PHP inside an HTML web page. The above preview has it enabled for example. This only works with certain languages.
  • light — Toggle light mode which disables the gutter and toolbar all at once.
  • padlinenumbers — Controls line number padding. Valid values are false (no padding), true (automatic padding), or an integer (forced padding).
  • toolbar — Toggle the toolbar containing the helpful buttons.
  • wraplines — Toggle line wrapping.

Some example shortcodes:

1
1
1
1

Shortcode Parameters

These are the parameters you can pass to the shortcode and what they do. For the booleans (i.e. on/off), pass true/1 or false/0.
lang or language — The language syntax to highlight with. You can alternately just use that as the tag, such as

code

. Click here for a list of valid tags (under “aliases”).
autolinks — Toggle automatic URL linking.
classname — Add an additional CSS class to the code box.
collapse — Toggle collapsing the code box by default, requiring a click to expand it. Good for large code posts.
firstline — An interger specifying what number the first line should be (for the line numbering).
gutter — Toggle the left-side line numbering.
highlight — A comma-sperated list of line numbers to highlight.
htmlscript — Toggle highlighting any extra HTML/XML. Good for when you’re mixing HTML/XML with another language, such as having PHP inside an HTML web page. The above preview has it enabled for example. This only works with certain languages.
light — Toggle light mode which disables the gutter and toolbar all at once.
padlinenumbers — Controls line number padding. Valid values are false (no padding), true (automatic padding), or an integer (forced padding).
toolbar — Toggle the toolbar containing the helpful buttons.
wraplines — Toggle line wrapping.

Some example shortcodes:

your code here
your code here
your code here
your code here
Share
No comments yet.
*