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

Direct access to the query engine
Relevanssi can’t be used in any situation, because it checks the presence of search with the is_search() function. This causes some…
Integrating Post Views Counter stats

…in the weight calculations is straightforward. The best tool to use is the relevanssi_results filter hook. It lets us modify the weights of the posts. For each post, we calculate a weight multiplier based on the visitor stats and then multiple the weight of the post with that. I add……= 1; } $relevanssi_pvc_weights[ $post_id ] = $weight; } } return $relevanssi_pvc_weights[ $post_id ] ?? 1; } add_filter( ‘relevanssi_results’, ‘rlv_pvc_weights’ ); function rlv_pvc_weights( $post_weights ) { foreach ( $post_weights as $post_id => $weight ) { $post_weights[ $post_id ] = rlv_pvc_weight( intval( $post_id ) ) * $weight; } return $post_weights; }……$relevanssi_pvc_weights[ $post_stats->id ] = $post_stats->count; } $max_visits = max( $relevanssi_pvc_weights ); $factor = $max_visits / 1000; // This controls the normalization. foreach ( $relevanssi_pvc_weights as $post_id => $visits ) { $weight = $visits / $factor; if ( $weight < 1 ) { $weight = 1; } $relevanssi_pvc_weights[ $post_id ] =…

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