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

Multi-part excerpts

Relevanssi Premium 2.11 introduces a new feature: multi-part excerpts. There’s a new setting on the Excerpts & Highlights settings tab, “Number of excerpt snippets”, and that lets you define the maximum number of excerpt snippets Relevanssi generates for each post. How does it work This option is only available when……the excerpt length is defined in words. If the excerpt length is defined in characters, the option still appears, but has no effect: there’ll be just one excerpt snippet for each post. This is the maximum number of excerpt snippets. If Relevanssi can’t find enough good excerpts, for example if……knows that and you can display that information on the search results page: Achieving this is a two-part process. First, add this to your site to modify the excerpt part with the relevanssi_excerpt_part filter to show the source data: add_filter( ‘relevanssi_excerpt_part’, ‘rlv_excerpt_parts’, 10, 2 ); function rlv_excerpt_parts( $excerpt_text, $excerpt )…

Sorting search results

If you want something else than the default relevancy ranking, you can use orderby and order parameters for the search query. Orderby accepts $post variable attributes and order can be asc (ascending) or desc (descending). The most relevant attributes here are most likely post_date and comment_count. If you want to…

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