How to add a custom class attribute into code wrapper? [duplicate]

To add your custom class to the old posts at once, you can do this via “the_content” filter and using preg_replace or preg_replace_callback function to do a REGEX replacement.

A working Example:

add_filter( 'the_content', function( $content ){

    // Don't do anything if we're not in a single post
    if(! is_singular()){
        return $content;
    }

    $customClass="custom-class";

    return preg_replace_callback(
        '/<pre([^>]+)class="([^"]+)"/i',
        function( $matches )use( $customClass ){
            return '<pre' . $matches[1] . 'class="' . trim($matches[2]) . ' ' . $customClass . '"';
        },
        $content
    );

} );