• Hi there,

    we are using Beaver Builder for creating our content pages and Relevanssi for the search which are working fine together in general. But we have some troubles with one BB module that renders a related posts block which will be indexed by Relevanssi. I would like to block the whole HTML node that holds this related content block. So I came across the two filters relevanssi_post_content and relevanssi_excerpt_content but I am not able to write the correct regular expression, I guess. My current code in the functions.php of our theme:

    add_filter( 'relevanssi_post_content', 'koe_rlv_pre_code', 10 );
    add_filter( 'relevanssi_excerpt_content', 'koe_rlv_pre_code', 10 );
    function koe_rlv_pre_code( $content ) {
        $content = preg_replace( '/<div id="related-stories-row"(.*)<\/div>/s', '', $content );
        return $content;
    }

    As you can see, the surrounding div has the id related-stories-row which I am trying to address. But it doesn’t work. Any tips for me?

    Thanks in advance!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Mikko Saari

    (@msaari)

    The catch here is that when relevanssi_post_content and relevanssi_excerpt_content run, shortcodes haven’t been expanded yet, so the post content doesn’t have the HTML code yet, but instead the shortcodes BB uses internally.

    That probably makes it slightly easier to just pluck out the shortcode for the unwanted module.

    Pro tip: add a var_dump( $content ); exit(); as the first line of the function, then go save a post, and you’ll see exactly what Relevanssi is seeing at that point.

    Thread Starter Christian Leuenberg

    (@cleuenberg)

    Thanks @msaari! BB doesn’t use shortcodes and var_dump( $content ); exit(); didn’t work as expected but instead I simply looked into the wp_posts.post_content database field in order to get the actual HTML code. Now I was able to find the code block and rewrite my preg_replace pattern in the function.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Blocking HTML parts’ is closed to new replies.