Better Source Code Posting

For the coders among you, you may already know that posting source code is really easy here on WordPress.com thanks to the sourcecode shortcode. You just wrap your code in [sourcecode] and you’re good to go — no code escaping or anything.

If you are one of those code posters, or are looking to become one, then you’ll be happy to know that we’ve updated the feature allowing more flexibility as well as adding support for additional coding languages like Bash and SVN diff.

See for yourself — here’s some HTML with a little bit of PHP:

<!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>WordPress.com Code Example</title>
</head>
<body>
	<h1>WordPress.com Code Example</h1>

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

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

	<p>This line is very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very long.</p>

	<div class="foobar">
		This	is	an
		example	of	smart
		tabs.
	</div>

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

Besides a completely new, easier to use look, you may notice that line number 12 is highlighted. It’s just one of the many new features offered in the new version which also includes things like first line number control and the much better toolbar (hover over the code block to make it show up).

To see the full list of available languages and configurations parameters as well as some working examples, check out our in-depth support document.

This feature was implemented using Alex Gorbatchev’s SyntaxHighlighter package. It’s also available as a plugin for WordPress.org users.

Leave a Reply

Your email address will not be published. Required fields are marked *

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image