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;
}
Facebook
X
LinkedIn
Email
Print

About the Author

Jason is the founder and owner of Greenville Webworks, a WordPress web design and development company based in Greenville, South Carolina. With over 20 years of experience building websites, he’s worked directly with small and medium-sized businesses across a wide range of industries — from restaurants and nonprofits to e-commerce and professional services — designing modern, mobile-responsive sites built on current web standards and best practices. Jason works hands-on with every client, from initial strategy through launch and ongoing support. Get in touch if you’d like to talk about your next website project.