February 11th in Wordpress by .

How to post source code in WordPress posts?

Quite often you might want to post code in your wordpress posts (HTML, SQL, CSS, PHP, Javascript etc..) in your wordpress posts but wordpress breaks the code and hides them inside html. Even placing the source inside pre and code tags wont work.

The easy way to do this is use syntax highlighter plugin which is available free from wordpress site. It supports many programming languages and shows the source code in neat formatted line numbers and colored formatting. The plugin shows the source code like this..

wpmcode.PNG

The syntax highlighter plugin supports many languages like…

* JavaScript — js, jscript, javascript
* PHP — php
* HTML/XHTML
* XML
* SQL
* VB
* C++
* C#
* CSS
* Delphi
* Java

and many more languages…

Installation

1. Download Syntax Highlighter plugin.
2. Upload it to your wordpress inside /wp-content/plugins/ folder
3. Activate the plugin under wordpress plugins.
4. Go to your theme folder and open footer.php and place

<?php wp_footer() ?>

before closing body tag of the file.

Note: If you dont place this line, then syntax highlighter will not work and it would just convert your source code to pre tag and there will no syntax highlighting.

Usage

Once you have installed and activated the plugin you can enclose the source code by any one of the following tags. Just specify the programming language within single quote

source.PNG

Similar Posts:

One Comment

  • martin slattery
    February 9, 2011

Leave A Comment.