Part two of this- it might also be a workable solution for me to remove the autoembed disabler. However I am unable to get this to work using the snippet you provide. Does it need a priority?
It shouldn’t, it’s the default priority. If you’re removing this in theme functions.php, you’re probably removing it before it’s added. Do it later:
add_action( 'init', function() {
remove_action( 'relevanssi_pre_the_content', 'relevanssi_kill_autoembed' );
}, 99 );
Hello Mikko,
Thanks for your response. I’ve tried adding the code you provided in the functions.php of my child theme, but the embed urls are still appearing in Relevanssi’s excerpts.
As in my first post, I’d be happy to just hide the embed url in the excerpt if that is easier.
You can use the relevanssi_excerpt_content filter hook to filter out the embed URL.
-
This reply was modified 4 years, 10 months ago by
Mikko Saari.
I was able to cobble together the following (Edited from this regex and your example for the filter), which seems to be working to remove YouTube and Vimeo urls other than for videos embedded in Woocommerce products:
add_filter( 'relevanssi_excerpt_content', 'sly_remove_youtube_vimeo_urls' );
function sly_remove_youtube_vimeo_urls( $content ) {
return preg_replace( '#^(http:\/\/|https:\/\/)((player\.)?vimeo\.com|youtu\.be|www\.youtube\.com)\/([\w\/]+)([\?].*)?$#im', '', $content );
}
Is a different filter required to work with relevanssi’s excerpt for Woocommerce products?
If the WooCommerce products are showing a Relevanssi-generated excerpt, the same filter should apply to them, it’s the same excerpt. If they’re showing something else, then I don’t know.