Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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?

like image 372
Q_Mlilo Avatar asked Feb 08 '11 08:02

Q_Mlilo


1 Answers

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!

like image 170
Michelle Avatar answered Oct 21 '22 13:10

Michelle