Displaying code in a Wordpress post by Lloyd Armbrust


There are many ways to display code in a WP post. You could wrap your code with the pre tag:

<pre>

Or, the xmp tag will tell your browser to ignore its rendering engine:

<xmp>

But if you’re trying to display PHP or JS, things will still not render correctly.

On this weblog, we use a WordPress plug-in called SyntaxHighlighter Plus. It was adapted for WordPress by people like Fred Wu and Matt Mullenweg from Google’s SyntaxHighlighter JavaScript package by Alex Gorbatchev.

  1. Download it here: http://wordpress.org/extend/plugins/syntaxhighlighter-plus/
  2. Upload and install it to your WP plug-ins directory.
  3. Then wrap your code with: [sourcecode language='php']..[/sourcecode]

Make sure to match the “language” attribute with the language of the code you’re wrapping:

  • cpp
  • csharp
  • css
  • delphi
  • html
  • java
  • jscript
  • php
  • python
  • ruby
  • sql
  • vb
  • xml

And that’s it, it should work like this:

<?php
echo "Your plug-in is working!"
?>

4 Responses to “Displaying code in a Wordpress post”

  1. eckert Says:

    sweet!

  2. Lloyd Armbrust Says:

    I know. It is.

  3. jack23 Says:

    I was wondering what that was.

  4. senseforweb Says:

    “Displaying code in a Wordpress post ” is really nice post. Thank you for share.

Leave a Reply


It’s Called Web Design is proudly powered by WordPress
Entries (RSS) and Comments (RSS). Valid XHTML