relevanssi_page_builder_shortcodes

apply_filters( 'relevanssi_page_builder_shortcodes', array $shortcodes, string $context )

Filters out page builder shortcodes that cause garbage data in Relevanssi index and excerpts.

Parameters

$shortcodes
(array) An array of shortcodes to remove.

$context
(string) The name of the current filter, generally relevanssi_post_content or relevanssi_pre_excerpt_content.

More information

Page builders like Divi, Visual Composer, Elementor, Fusion Builder, WPBakery and others use shortcodes to build the page layouts and include elements. These shortcodes can be a problem with Relevanssi, as they can appear in the Relevanssi excerpts and cause Relevanssi to index all kinds of garbage metadata that should not be in the index.

To solve this, Relevanssi removes many of these shortcodes in the indexing and excerpt-building process. For some shortcodes, Relevanssi removes both the tag and the contents (for example et_pb_sidebar, vc_raw_html or fusion_imageframe) and for the rest, Relevanssi only removes the tags.

This process happens in the relevanssi_post_content and relevanssi_pre_excerpt_content filter hooks. Relevanssi introduces the default behaviour like this:

add_filter( 'relevanssi_pre_excerpt_content', 'relevanssi_remove_page_builder_shortcodes', 9 );
add_filter( 'relevanssi_post_content', 'relevanssi_remove_page_builder_shortcodes', 9 );

So, if you’re looking into doing any filtering that requires the presence of the page builder shortcodes, add it to those filter hooks on a lower priority than 9. The default priority of 10 is already too late, and you’ll see just the filtered content without the shortcodes.

Relevanssi lists the shortcodes in the array as regex patterns, so if you add your own, make sure to add them as regex patterns. Relevanssi feeds the whole array to preg_replace() and each entry is replaced by a space.

Here’s the default array:

array(
  // Remove the tag and the content.
  '/\[et_pb_code.*?\].*\[\/et_pb_code\]/im', // Divi
  '/\[et_pb_sidebar.*?\].*\[\/et_pb_sidebar\]/im', // Divi
  '/\[et_pb_fullwidth_slider.*?\].*\[\/et_pb_fullwidth_slider\]/im', // Divi
  '/\[et_pb_fullwidth_code.*?\].*\[\/et_pb_fullwidth_code\]/im', // Divi
  '/\[vc_raw_html.*?\].*\[\/vc_raw_html\]/im', // Visual Composer
  '/\[fusion_imageframe.*?\].*\[\/fusion_imageframe\]/im', // Fusion Builder
  '/\[fusion_code.*?\].*\[\/fusion_code\]/im', // Fusion Builder
  // Remove only the tags.
  '/\[\/?et_pb.*?\]/im', // Divi
  '/\[\/?vc.*?\]/im', // Visual Composer
  '/\[\/?mk.*?\]/im', // WPBakery
  '/\[\/?cs_.*?\]/im', // ThemeCo Cornerstone
  '/\[\/?av_.*?\]/im', // Avia Builder
  '/\[\/?fusion_.*?\]/im', // Fusion Builder
  // Other problematic plugins.
  '/\[maxmegamenu.*?\]/im', // Max Mega Menu
  '/\[ai1ec.*?\]/im', // All-in-One Event Calendar
  '/\[eme_.*?\]/im', // Events Made Easy
  '/\[layerslider.*?\]/im', // Layerslider
  '/@ET-DC@.*?@/im', // Divi metadata
),