Skip to main contentSkip to footer

CodeMirror Blocks is a good plugin for displaying good-looking code blocks in WordPress (you can see it in action right here on Relevanssi.com!). There’s a problem with Relevanssi in-document highlighting and the CodeMirror block, though: enabling the highlighting will break all CodeMirror blocks on the page, even if the highlighting happens outside the block.

This problem happens because CodeMirrors stores the block parameters in a settings attribute, and Relevanssi in-document highlighting breaks that attribute. Fortunately, this is easy to fix with a filter function that runs after the Relevanssi in-document highlighting and fixes the broken attribute. Add this to your theme functions.php:

add_filter( 'the_content', 'rlv_restore_codemirror_settings', 12 );
function rlv_restore_codemirror_settings( $content ) {
    $data_settings_found = preg_match_all( '/data-setting="{(.*)}"/', $content, $data_settings );
    if ( $data_settings_found ) {
        foreach ( $data_settings[1] as $data_setting ) {
            $content = str_replace( $data_setting, htmlentities( $data_setting ), $content );
        }
    }
    return $content;
}

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

Italian plurals
A Relevanssi user asked about Italian plurals on the Relevanssi support forums. The best answer is to use the Relevanssi…
Filtering results by category
In order to filter search results by category, use the following code: $url = get_bloginfo('url'); $url = esc_attr(add_query_arg(array('cat' => '10',…

Related Posts:

Currently there are no related posts available.

Comment Section:

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed