Created
October 6, 2020 04:03
-
-
Save the-sufi/e4f5d04d97f9dd41b837e7017dfaef39 to your computer and use it in GitHub Desktop.
Remove Visual Composer shortcodes from Relevanssi search result
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* When using relevanssi search with visual composer, search results come with some vc_* shortcode. | |
* Relevanssi by default removes some of the shortcodes. Sometimes theme also include some custom vc shorttcode. | |
* This code will remove all of those unwanted vc_* shortcodes from search result. | |
* | |
* Goes inside functions.php of active theme | |
*/ | |
add_filter( 'relevanssi_pre_excerpt_content', 'dctit_vc_filtered_content', 99 ); | |
add_filter( 'relevanssi_post_content', 'dctit_vc_filtered_content', 99 ); | |
function dctit_vc_filtered_content( $content ) { | |
$content = preg_replace('/\[\/?vc_.*?\]/', '', $content); | |
$content = preg_replace( '/\[vc_.*?text="(.*?)".*\]/im', '', $content ); | |
$content = preg_replace( '#\[[^\]]+\]#', '', $content ); | |
return $content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment