WordPress is converting & to & inbetween [code] brackets

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/

Leave a Comment