If you want to display code snippet in posts without a plugin put following code in your theme’s functions.php file.

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

To display snippets in your post, you can use the shortcode to remove WordPress auto-formatting.

[ code]<?php echo 'Hello World!' ?>[/ code]
Source: https://www.isitwp.com/code-in-posts/

Leave a Comment

You must be logged in to post a Review.