Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

When I post a PHP code snippet into a wordpress post it will convert

<?PHP into <!--?PHP

To avoid this I must replace <?PHP with &lt;?PHP

I am asking if there is a setting or easy method to avoid this? If not I am thinking of maybe writing a PHP function that will search the content filed and replace <?PHP with &lt;?PHP

Any ideas

share|improve this question

2 Answers 2

PHP is filtered out of the WordPress post editor as a security feature. There are some plugins that let you put them in, but I think they're a pretty bad idea, so I won't even link to them.

If you need PHP on a page, you should be putting that code in a template file or in functions.php or a plugin file that hooks to a page you want to modify.

share|improve this answer
    
Hello sorry I wasn't clear, I am posting code for my syntax highlighter to show the code on the screen, not run the code. I used to use a syntax plugin but now I am using my own. Maybe my old syntax highlighter filtered this for me and I didn't realize it –  jasondavis Aug 26 '12 at 23:44
    
Aha. I understand. I suspect you're right that this is getting filtered out. I like Syntax Highlighter Evolved from Automattic. (wordpress.org/extend/plugins/syntaxhighlighter) –  mrwweb Aug 26 '12 at 23:57
    
That is the plugin I have always used but I just switch to the new Rainbow.js its more lightweight and better IMO craig.is/making/rainbows –  jasondavis Aug 27 '12 at 0:01
    
If you take a look at Syntax Highlighter (plugins.trac.wordpress.org/browser/syntaxhighlighter/tags/3.1.2/…) evolved you'll see that it's way more than just a JS highlighting library. I don't see why you'd want to reinvent the wheel on this one. –  mrwweb Aug 27 '12 at 0:44
    
That plugin is simply a wrapper for Alex Gorbatchev JS highlighter, the only "other" stuff it does is detect which brush files to load and a few other minor things... It's a great library but it's a bit outdated and better JS highlighters are on the market now like Rainbow.js much better performace, also this new one Prism from Lea Verou. I't not re-inventing the wheel its taking an old sluggish library and replacing with a new fast one –  jasondavis Aug 27 '12 at 10:20
up vote 0 down vote accepted

Here is my only idea so far

function strip_php($content) {
    return str_ireplace("<?PHP", "&lt;?PHP", $content  );
}
add_filter('content_save_pre','strip_php');
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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