I am using this plugin: http://www.megatome.com/syntaxhighlighter/

Which appears to work ok, minus a few glitches here and there.

My problem, is that I think WordPress is rewriting <?php with <!--?php and other tags, presumably for security.

Is there any way to disable this functionality, so that I can show code in it's full:

Here is some PHP in my text...<?php echo 'Foo'; ?>

rather than having to choose between no <?php tags and having messed up output.

I ask, because often I write about code that goes in and out of PHP, so having the tags in place is crucial really.

Hope this makes sense, and thank you.

-- on a side note, is there any way to prevent wordpress parsing the following:

<pre class="brush:php;">
return '<img src="' . $my_img . '" />';

WordPress will attempt to find an image rather than just output the code, causing all kinds of problems.

Long story short - what's the best way of showing PHP code on a wordpress blog without having to worry about wordpress breaking the output.


2 Answers 2


Indeed, you need to convert the code to their HTML entities to prevent WordPress (or the TinyMCE editor) from stripping it out. The Visual editor does some of this work for you, in the HTML editor you must do this yourself.

Fortunately, there are syntax highlighter plugins (also based on the same SyntaxHighlighter Javascript library) that do this for you, like SyntaxHighlighter Evolved. With this plugin you can write [php]Your <?php echo 'code'; ?>[/php] and it will escape and highlight it. (There are other shortcodes too of course, [php] is just a shorthand.)

  • I've tried many plugins over the years and SyntaxHighlighter Evolved has worked the best for me. Highly recommended.
    – mfields
    Jul 17, 2011 at 18:11

Unfortunately, this is a limitation of the underlying JavaScript library when using the <pre/> tags. The only solution is to replace any < tags you have with &lt;. It's not the most elegant of solutions, but it's a pretty easy find and replace.

I've actually updated the info at http://megatome.com/syntaxhighlighter to include this information.

You can see some more information about this issue here: http://alexgorbatchev.com/SyntaxHighlighter/manual/installation.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.