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.

I installed a syntax highlighter plugin so I could post and highlight code snippets.

My problem is wordpress is converting special characters in my code (e.g. from & to &), when I really just want it to leave my code alone.

share|improve this question

1 Answer 1

I tracked this solution down from the WordPress Trac ticket found here: http://core.trac.wordpress.org/ticket/6969

The solutions seems to be to add this to your functions.php file:

<?php 
function foobar_run_shortcode( $content ) {
    global $shortcode_tags;

    // Backup current registered shortcodes and clear them all out
    $orig_shortcode_tags = $shortcode_tags;
    remove_all_shortcodes();

    add_shortcode( 'foobar', 'shortcode_foobar' );

    // Do the shortcode (only the one above is registered)
    $content = do_shortcode( $content );

    // Put the original shortcodes back
    $shortcode_tags = $orig_shortcode_tags;

    return $content;
}

add_filter( 'the_content', 'foobar_run_shortcode', 7 ); ?>

Source: http://www.viper007bond.com/2009/11/22/wordpress-code-earlier-shortcodes/

REVISED ANSWER:

I've tried the solution above, but I've not had any luck getting it to work. I've actually being trying different methods for the same problem with some luck, but none of them really work 100% without completely removing wp_autop and wp_texturize. I have found a way, but it takes an extra step. I'll post my solution in case your interested.

My Way:

  1. First copy your php code
  2. Go to http://quickhighlighter.com/
  3. Paste your code into the textarea
  4. Click Highlight!
  5. When the code pops up, click the "Toggle Code View" link
  6. Copy the Code (not the css, but the HTML)
  7. Go to your post edit screen and select the post your adding the code to
  8. Click on HTML View
  9. Paste the code into the editor and click save (switching from HTML to Visual won't break the code since it's in HTML format and the characters have already been converted) The CSS Provided by the highlighter doesn't quite work (it isn't wrapped, and is full page).

You can use the CSS I've put together if you like: http://snipplr.com/view/58362/wordpress-code-highlighter-css/

share|improve this answer
    
You can view a sample of the outcome here: wordpressexpression.com/the-blog. Forgive the theme, I'm in the beginning of developing a new theme and it's a little bit ugly right now. –  Jeremy Jared Sep 1 '11 at 0:48

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.