Wordpress and php code in my posts

I am enclosing a php command within < pre > tags so I can show some code to my readers, however wordpress is removing the whole php statement, how can i get around this? im also using the wp syntax plugin although i dont think this should affect anything

Does it help if you also enclose it in the <code> element?

(just having a guess, I don’t have that problem)

no still the same problem even if i add the code element

any more help on this please?

If you want to include code examples within a post you will not be able to use < and > you will have to use < and > so it would be: <?php… ?>

Edit: Or maybe not, as I just looked at some old code samples on my blog and they’re just surrounded with <pre lang=“html”></pre>

ok, thought i could include them within pre tags, maybe i was mistaken

Honestly it’s been ages since I’ve looked at WP’s markup prettifier. It’s possible also that it is removing those statements because they could potentially be dangerous.

When you say it’s removing them, is it while you edit (the wysiwyg editor is a frequent pest) or after you save? Perhaps it would help you to use the HTML editor instead of the wysiwyg.

Also, I’m sure you’ve already looked at this:
http://codex.wordpress.org/Writing_Code_in_Your_Posts

But do take a look again down the bottom, where there’s a list of plugins and resources that may make this easier for you.

The codex link raena posted is the best reference, but try changing $ to &#36;

Change to the visual editor, enter the code in, then switch to “HTML mode” so that you can add the <pre> or <code> tags. The visual editor automatically converts everything to entities.

I wrote a plugin recently which allows you to enter raw HTML directly into the comments section of a site, and I assume it would be just a matter of hooking it into the_content() to get it working with the post area as well. We’re not allowed to link to our own stuff around here though so I can’t show it to you.

I switched plugins to a combo of Visual Code Editor and SyntaxHighlighter Plus, although I didnt manage to get it working perfectly either. Now I’m having a space inserted between the opening bracked and the question mark:

< ?php © Copyright 2009 - <?php echo (date(“Y”)); ?>

instead of:

<?php © Copyright 2009 - <?php echo (date(“Y”)); ?>

In my visual editor I’m using this syntax
[sourcecode language=“php”]<?php © Copyright 2009 - <?php echo (date(“Y”)); ?>[/sourcecode]

Your PHP doesn’t make any sense.

Have you tried just using the visual editor yet? I’m pretty sure all of your problems are just caused by incorrect syntax which can be avoided by using the visual editor to convert everything to entities.

i need the plugins for longer bits of code that’s why im using them. I am inserting the code through the visual editor

my php was indeed incorrect, this is the correct version

© Copyright 2009 - <?php echo (date(“Y”)); ?>

wordpress still displays an extra space between the bracket and the question mark:

© Copyright 2009 - < ?php echo (date(“Y”)); ?>

I use Syntax Highlighter Post to put code in my posts. The main benefit over PRE & using the HTML side of things is you can Copy & Paste from it directly to a notepad document (without having special characters rendered).

Like rhy, I use CodeColorer, same thing basically

testing