Last update: November 18, 2020

Fix your WordPress search with Relevanssi

UPDATE

Great news, with the last version of Relevanssi (v4.9.0), Oxygen is supported and we don't need to do anything :

New feature: Improved compatibility with Oxygen Builder. Relevanssi automatically indexes the Oxygen Builder content and cleans it up.

 

Adding a search form with oxygen is very easy. There is an element for that.
Customizing the search result page is also very easy. We can create a template for that.

But did you know that all the content we write in the Oxygen editor is stored in a custom field called ct_builder_shortcodes ?
And by default, the WordPress search engine only searches in pages and posts but not in custom fields.
So if you write your articles in Gutenberg, it's fine, but if you write them in the Oxygen editor, the search won't find anything from them.

Relevanssi to the rescue

There are other search plugins that can add custom fields to the search engine. But Relevanssi has some sweet features:
It's free (there is also a premium version), it has some filter hooks and we don't need to add a shortcode as it will work directly with the default search form.

Adding the Custom Field content

In the Relevanssi Search Options, click on the Indexing tab:

Go to the Custom fields option, select some and add ct_builder_shortcodes :

It could be enough but still, there is a little thing that needs to be fixed.

Getting rid of the shortcodes

The oxygen content is filled with lots of shortcodes. And these shortcodes will be added in the search content. Which makes the search not always relevant.

Here is an example.
At the top we can see the original content of the custom field. At the bottom it's the same content minus the shortcodes.
And in blue, it's the shortcodes we want to get rid of.

If we keep the shortcodes, and someone types some keywords like 'display', 'position', 'flex', most pages will show up in the result because these keywords are often used in the Oxygen shortcodes. Even if your articles don't mention them at all.

By chance, Relevanssi has lots of filter hooks, so we can easily filter the custom field values before indexing the content.
And to remove the shortcodes, we can simply use a regular expression.

add_filter( 'relevanssi_custom_field_value', 'rlv_custom_field_shortcodes' );
function rlv_custom_field_shortcodes( $content ) {
    $content = preg_replace( '/[.*?]/s', '', $content );
    return $content;
}

Copy and paste this code in the plugins.php file from the plugin "My Custom Functionality".
More info : HOWTO

Building the index

The final step is to build the index.
Go back to the settings and click on the Build the index button:

That's it, it's done, you can try your search form.

You can also check the other options.  My settings for OXYGEN4FUN:

Huge thanks to Mikko Saari, the author of this plugin. He answered me the same day I asked questions in the WordPress support page.
Awesome support!

 

closealign-justifychevron-downcaret-up