Skip to main contentSkip to footer

I need to add some custom shortcodes to the list of the “removed” ones (so they don’t show in plain text in the results).

However, some of them are built like [shortcode_name text="Need to keep this in results"] and I would like the content in the text parameter to stay in the results.

How do I go about this?

– Duke at Remove shortcode but keep content in X parameter

You can’t do this using the Relevanssi shortcode removal because that’s a binary operation: the whole shortcode is kept or removed, and there’s no way to keep only part of the shortcode.

However, you can do this with the relevanssi_post_content filter hook by removing the shortcode while keeping the attribute text. To get the same effect in excerpts, you can add the same filter function to the relevanssi_pre_excerpt_content filter hook.

add_filter( 'relevanssi_pre_excerpt_content', 'rlv_shortcode_attribute', 8 );
add_filter( 'relevanssi_post_content', 'rlv_shortcode_attribute', 8 );

/**
 * Indexes only the "text" attribute from the 

This is custom heading element

shortcode * * @param string $content Post content * * @return string Post content with the shortcode replaced with just the "text" attribute content. */ function rlv_shortcode_attribute( $content ) { return preg_replace( '/\

This is custom heading element

/im', '\1', $content ); }

Since this particular case was about a Visual Composer shortcode, it’s worth noticing the new filter must happen on priority 8 or earlier, because on priority 9, Relevanssi runs the relevanssi_remove_page_builder_shortcodes() function that removes all Visual Composer shortcodes, including this vc_custom_heading. As long as the new filter runs before the default function, there’s no problem.

Your account

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

Search

Popular Resources

Divi

Make Divi include all post types Divi search form module restricts the search to only posts and pages. To get rid of that restriction, you can add this to your site: add_action( ‘pre_get_posts’, function() { unset( $_GET[‘et_pb_searchform_submit’] ); }, 1 ); Divi and multisite searching Divi search results templates don’t……work in multisite searching. Multisite searching requires changes to the templates, and it’s impossible to make those changes in the Divi Blog module. If you want to do multisite searching with Divi, you need to use a standard WordPress search results template for the results. Getting Divi to show Relevanssi……excerpts Divi doesn’t use the default excerpts but instead truncates the beginning of the post and shows the first 270 characters. That means Relevanssi-generated excerpts don’t show up at all. However, you can configure Divi to show Relevanssi excerpts. Just enable the “Use excerpts when defined” setting in Divi settings,…

German umlauts
By default, the search ignores German umlauts. Searching for “uber” will also find “über” and so on. This ignorance is…
Keyword-based search blocking
Update: In Premium 2.15.0 and later versions, you can do spam blocking from Relevanssi settings. Just navigate to the Spam…

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