tags:

views:

189

answers:

7

I just started a coding related wordpress bog to basicly discuss topics and store code snippets in. I installed a code syntax highlighter plugin which is very nice but I am having a problem. I just tried posting my first code related blog post and wordpress seems to only post some of my code and then it makes some of it not show, like it filters some of it out even though I am wrapping it in tags like this..

<pre class="brush:php">

<?PHP
my code
?>

</pre>

Some of my code works and some gets filtered out somehow. I know this is possible as many wordpress coding sites show source code. Do I need to modify something to make it work in wordpress?


UPDATE

I have confirmed that it does save ALL my code into the database it just filters it out when it try to print to screen, so when I go in to edit the post and textbox populates with ALL the source code intact

+1  A: 

Did you read this Codex article? For highlighting code you can use wordpress plugins.

ZhukovRA
Yeah I read over that, it does't sound to promising. I even tried a plugin that is supposed to preserve code but it still didn't work with some of my PHP code. Also I have no problem highlighting code, I have a plugin for that my problem is the wordpress code is filtering certain code out of my posts
jasondavis
+2  A: 

My guess is that you have unfiltered < or & signs in your code that need to be encoded. Use "&lt;" for < and "&amp;" for &.

Gabe
Yeah probably I just thought these plugins were supposed to make it change them for me
jasondavis
A: 

Did your <?php ?> codes get executing?

Try with <?php phpinfo(); ?> to confirm that.

S.Mark
A: 

I tried about 3 different plugins and with them all combined I finally have wordpress not filtering out my php code

jasondavis
and this would probably be the place where you should include the names of those plugins?
Wade Tandy
A: 

I use WordPress › WP-Syntax « WordPress Plugins and there are no problems with posting and formating php, css, applescript, etc. You must not have the plugin(s) installed correctly.

songdogtech
A: 

take a look at http://en.support.wordpress.com/code/posting-source-code/ that's what the official wordpress hosting supports, it's really easy to use and should be tested enough.

diega
A: 

Hi,

I have had a lot of trouble with inserting codes into wordpress posts in the past, but I did find a very easy way to do it! I would add this code to your stylesheet:

pre  {
font-family: courier,"courier new",monospace;
font-size: 12px;
overflow-x: auto; /* Use horizontal scroller if needed; for Firefox 2, not needed in Firefox 3 */
white-space: pre-wrap; /* css-3 */
white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
/* width: 99%; */
word-wrap: break-word; /* Internet Explorer 5.5+ */
  }

And then just make sure whatever code you are trying to display as code is within the < pre > tags. Works great for me!

I just wrote a blog post about this too (http://blog.thelibzter.com/displaying-snippets-of-code-correctly-in-wordpress-posts) since it was something that I could not find a solution to for a long time! Hope that helps!

Libby