UncategorizedWordpress

Preventing Shortcodes from Showing up in Relevanssi Search Results

By January 27, 2019 January 27th, 2020 No Comments

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;
}
Jason Pleakis

Jason Pleakis

Jason has over 10 years of experience developing in Wordpress and is the owner of Greenville Webworks. His Greenville, South Carolina company designs and develops modern websites for clients in a variety of industries using the latest web standards and practices.