Preventing Shortcodes from Showing up in Relevanssi Search Results

Sometimes shortcodes appear in Relevanssi search results. There is a simple way to filter them out. Copy & Paste the code below into your theme’s functions.php file and replace ‘vc_’ or ‘divider’ with the name of your shortcode.

When you’re done, you need to go into the Relevanssi settings and re-index the site to see the results.

For removing Visual Composer Shortcodes:

add_filter('relevanssi_pre_excerpt_content', 'trim_rv_shortcodes');
function trim_rv_shortcodes($content) {
     $content = preg_replace('/\[\/?vc_.*?\]/', '', $content);
     return $content;
}

For removing shortcodes that begin with ‘divider’:

add_filter('relevanssi_pre_excerpt_content', 'trim_rv_shortcodes');
function trim_rv_shortcodes($content) {
     $content = preg_replace('/\[\/?divider.*?\]/', '', $content);
     return $content;
}