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?
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:
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!
Agree with @Michelle.
This actually works for me.
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.
Your pages will load faster if you do the syntax highlighting before posting, using pygmentize: http://permafrostcodingstudio.com/articles/syntax-highlighting-in-posts/
It’s a little more complicated, but worth being able to disable a plugin. WordPress will run faster and be more secure with fewer plugins installed.