Support » Plugin: Relevanssi - A Better Search » Remove shortcode but keep content in x parameter

  • Resolved Duke


    I need to add some custom shortcodes to the list of the “removed” ones (so they don’t know 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?

    Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Mikko Saari


    This can’t be done that way; either you remove the whole shortcode or keep it all. There’s no straightforward way to keep the shortcode attribute text.

    You need a filter function on relevanssi_post_content. The post content passes through this filter before the shortcodes are expanded. At this point, you can remove the shortcode tags from the content, while keeping the parameter text.

    Thread Starter Duke


    Ok thank you, it’s ok if I have to remove the whole thing I guess.
    Can you please assist with the reg expression?

    This is how the shortcode is built in full (an example):

    [vc_custom_heading text="Some text here." font_container="tag:h6|font_size:16px|text_align:left" use_theme_fonts="yes" css_animation="fadeIn"]

    Plugin Author Mikko Saari


    Here’s the thing:

    add_filter( 'relevanssi_pre_excerpt_content', 'rlv_vc_custom_heading', 8 );
    add_filter( 'relevanssi_post_content', 'rlv_vc_custom_heading', 8 );
    function rlv_vc_custom_heading( $content ) {
    	return preg_replace( '/\[vc_custom_heading.*?text="(.*?)".*\]/im', '\1', $content );
    Thread Starter Duke


    @msaari worked like a charm! Thank you! 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Remove shortcode but keep content in x parameter’ is closed to new replies.