Skip to main contentSkip to footer

Relevanssi breaks autoembeds on result pages

You may notice that enabling Relevanssi custom excerpts breaks all autoembeds (things like Youtube video embeds) on search results pages. That’s done on purpose, because the autodiscovery of those embeds can be a proper performance killer if the search results include lots of embedded content. Thus, Relevanssi switches the feature off, considering it’s not commonly used on search results pages anyway.

But what if you do need it? There are three solutions for this, and choosing the right one depends on the circumstances:

  1. Disable Relevanssi custom excerpts.
  2. Remove the Relevanssi autoembed disabler.
  3. Don’t rely on the_content filter hook and instead use autoembed directly.

In general I recommend the option 3.

Disable Relevanssi custom excerpts

This one’s straightforward. Just disable Relevanssi custom excerpts, and this will no longer be a problem. Of course, you won’t get Relevanssi custom excerpts, either.

Remove the Relevanssi autoembed disabler

From the versions 2.14.4 (Premium) and 4.12.4 (free) onwards you can allow autoembed discovery with this line of code:

add_action( 'init', function() {
  remove_action( 'relevanssi_pre_the_content', 'relevanssi_kill_autoembed' );
}, 99 );

This will allow the autoembeds to work on the_content filter hook again. However, this may lead to performance problems. Try it out and see what happens. If the search becomes too slow, look for the next approach.

Use autoembed directly

Using apply_filters( 'the_content', $content_with_embed ) to do the autoembeds is not the ideal way to approach this in the first place. It does get the job done, but may have unwanted side effects for example from other plugins that do something with the_content hook. I think it’s better to use the autoembed functionality directly.

That’s easy. Instead of

echo apply_filters( 'the_content', $content_with_embed );

you do this:

$embed = new WP_Embed();
echo $embed->autoembed( $content_with_embed );

This will do the autoembedding without any side effects and with no interference from Relevanssi.

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

Menu problems in multisite search
Sometimes multisite searches cause problems in navigation menus. This is caused by pages from another subsite going into the page…
Modernize
Modernize is a neat Premium theme that has a problem with Relevanssi. Relevanssi highlighting can cause problems on Modernize search…
Debugging Relevanssi searching issues

Relevanssi searches as well – you can see the queries Relevanssi makes and notice unwanted query parameters appearing in the database queries. Here are some instructions on how to use Query Monitor. Look at the parameters Relevanssi is getting add_filter( ‘relevanssi_modify_wp_query]}**’, ‘rlv_check_parameters’ ); function rlv_check_parameters( $query ) { var_dump( $query->query_vars…); exit(); } If you add this and run a search, you’ll see the query parameters Relevanssi uses. Is there something there that doesn’t look right? For example, is there a taxonomy parameter that shouldn’t be there? Look at the MySQL query Use Query Monitor, or add this: add_filter( ‘relevanssi_query_filter’,……’rlv_check_mysql’ ); function rlv_check_mysql( $query ) { var_dump( $query ); exit(); } This shows the final MySQL query that is used. There’s one for each search term, so that’ll show the query for the first search term (which is not necessarily the word you entered first). Are there any unexpected…

Related Posts:

Comment Section:

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed