Displaying code snippets in WordPress

Ok, not technically a programming question but I want a plugin for my WordPress blog that displays code snippets.

Can anyone here recommend a good one? Also, do you guys know which one Jeff uses on codinghorror. That one looks really good.

Read More

Thanks.

Related posts

Leave a Reply

3 comments

  1. For WP-Snippets, I use Prettify.

    You should probably use a plugin for escaping characters to be able to display code without having to do it yourself, or your code wont be displayed. Or just put this in functions.php in your theme folder to do this automatically:

    function bbcode( $attr, $content = null ) {
        $content = clean_pre($content); // Clean pre-tags
        return '<pre"><code>' .
                str_replace('<', '&lt;', $content) . // Escape < chars
                '</code></pre>';
    }
    add_shortcode('code', 'bbcode');
    

    And then wrap your code with [code]<?php echo 'hello world!'; ?>[/code]

    Source: Code in posts