For WP snippets, I use Prettify .
You should probably use a character escaping plugin to be able to display the code without having to do it yourself, or your code will not be displayed. Or just put this in functions.php in the theme folder to do this automatically:
function bbcode( $attr, $content = null ) { $content = clean_pre($content); // Clean pre-tags return '<pre"><code>' . str_replace('<', '<', $content) . // Escape < chars '</code></pre>'; } add_shortcode('code', 'bbcode');
And then wrap your code with [code]<?php echo 'hello world!'; ?>[/code] [code]<?php echo 'hello world!'; ?>[/code]
Source: Code in Messages
source share