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.
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:
You can use the CSS I've put together if you like: http://snipplr.com/view/58362/wordpress-code-highlighter-css/
After trying everything under the sun to fix this issue, I was able to fix it by simply installing an older version of WP. You can easily install and use a WP plugin to do the downgrading. FWIW, I used a plugin called WP Downgrade. You can find it at wordpress.org.
After installing the plugin, it'll ask you for the WP version to downgrade to. (I went with 4.9.8 since I'm used to editing WP sites with this version). Hit the install. This will then show you a confirmation 'core' button. You then click this and confirm the install at the 'core' page. Very easy to do and the problem was solved in 5 ~ 10 minutes (ex: 1. Finding and installing the wp plugin. 2. Type in the wp version you want to downgrade to. 3. Click in the install button and 'core' install button.)
To people coming from a Google search, using the Crayon Syntax Highlighter and experiencing the same issue as noted in the OP:
Go to the Settings of Crayon Syntax Highlighter and tick on the option Decode HTML entities in code. This solves the issue.