WordPress syntax highlighting

I recently switched my blog from joomla to wordpress and i’m having problems when posting code snippets.

The editor seems to remove some of the characters when i save my posts.

Read More

I am using a plugin that i got from this link: http://alexgorbatchev.com/SyntaxHighlighter/

Example:

<pre class="brush: javascript">;
var window.onload = function() {
    alert("Loading is complete");
};
</pre>

Is formatted to:

<pre>;
var window.onload = function() {
    alert("Loading is complete");
};
</pre> 

How can i solve this problem?

Related posts

Leave a Reply

3 comments

  1. If you’re on WordPress.com, I believe you should be using a shortcode like so: http://en.support.wordpress.com/code/posting-source-code/

    If you’re on self-hosted WordPress and using the WordPress plugin Syntax Highlighter (http://wordpress.org/extend/plugins/syntax-highlighter/), again I think the correct way to insert code is by wrapping it in a shortcode. So instead of < pre > you would use:

    [javascript]
    // your code here
    [/javascript]
    

    If neither of these sounds like an ideal solution (or works) there are a bunch of other syntax highlighter plugins for self-hosted WordPress that might be better: http://wordpress.org/extend/plugins/search.php?q=syntax+highlighter

    Hope this helps – best of luck!

  2. Agree with @Michelle.
    This actually works for me.

    [sourcecode language='javascript']
        //Replace 'javascript' by the corresponding language
        //Your code goes here
    [/sourcecode]
    

    It will work on save or update for hosted and non hosted sites.
    Example.

    To apply it to your text, you just have to switch to the ‘Text’ visual editor.