Support » Plugin: Relevanssi - A Better Search » Shortcodes in search results

  • I have added a variety of scripts to the functions.php file to try to remove the visual composer shortcodes including using the script found here https://www.relevanssi.com/knowledge-base/divi-page-builder-and-cleaner-excerpts/ to remove all shortcodes.

    However, some of my results still have shortcode. I’m using Visual composer that came with a theme and there may be shortcodes that don’t start with vc_ but I’m not sure how to remove them. For example pages that have icons, buttons and dividers have issues.

    Since the script to remove all shortcodes didn’t work, i’ve tried instead:

    add_filter(‘relevanssi_pre_excerpt_content’, ‘rlv_trim_vc_shortcodes’);
    function rlv_trim_vc_shortcodes($content) {
    $content = preg_replace(‘/\[\/?vc_.*?\]/’, ”, $content);
    $content = preg_replace(‘/\[\/?iconbox.*?\]/’, ”, $content);
    $content = preg_replace(‘/\[\/?button.*?\]/’, ”, $content);
    $content = preg_replace(‘/\[\/?rd_line.*?\]/’, ”, $content);
    return $content;
    }

    But i’m still unsuccessful.

    The page I need help with: [log in to see the link]

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

    (@msaari)

    Can you please show me a screen shot of what the actual page HTML code looks like in the text editor in WP admin?

    Thread Starter skigirl1369

    (@skigirl1369)

    Thank you in advance for taking a look.

    I have uploaded screen shots of the WP admin source code from the text editor for two of the pages that appear to include shortcode in the search results.

    http://nimb.ws/rKHOwU

    Plugin Author Mikko Saari

    (@msaari)

    I’m not familiar with Visual Composer, but the garbage the final excerpt shows is not included in the page source code; it’s generated somewhere.

    Please add this to your theme functions.php:

    add_filter( 'relevanssi_pre_excerpt_content', 'rlv_test_pec', 8 );
    add_filter( 'relevanssi_pre_excerpt_content', 'rlv_test_pec', 11 );
    function rlv_test_pec( $content ) {
        var_dump( $content );
        return $content;
    }

    Then search for "cremation service locations" with the quotes and let me know what it prints out. Then remove the code, because it’ll print out lots of garbage for all searches.

    Thread Starter skigirl1369

    (@skigirl1369)

    I added the code to the functions file, cleared the cache, and then searched for the term specified with quotes. It still showed the same result for the location page. http://nimb.ws/xW0V6k

    I also tried another search and didn’t see any garbage returned per your comment.

    I activated excerpts on pages using

    // add page excerpt support 
    add_post_type_support( 'page', 'excerpt' );

    But the custom excerpt isn’t being used in search results.

    I tried to activate “Create Custom Search Snippets” but then the search results page broke. http://nimb.ws/6K4V2j

    I removed your code and then I could select “Create Custom Search Snippets” but it still didn’t help with using the custom excerpt on these pages. Is using the Excerpt field on a page a possible solution?

    Plugin Author Mikko Saari

    (@msaari)

    That broken page was exactly what the filter you added was supposed to print out.

    So you weren’t actually using Relevanssi-generated excerpts in the first place? That’s why the code you added originally did nothing: it only works for Relevanssi-generated excerpts. So, if you want me to help you here, you need to use excerpts generated by Relevanssi – that’s the one I can help you with, but if you don’t use them, then you need to ask elsewhere. Divi support can help you then.

    So, if you enable Relevanssi custom search snippets, what happens? Do you get better excerpts or not?

    Thread Starter skigirl1369

    (@skigirl1369)

    I am more than happy to use Relevanssi generated search snippets. Just need to know what to do…

    Do I add your code back in?

    Right now, i have “Create custom search result snippets” checked. But it’s showing the original results with some (but not all) snippets still having short code issues.

    Plugin Author Mikko Saari

    (@msaari)

    Ah, now I remember: Divi blocks the Relevanssi excerpts. You need to do some changes to your child theme to get working excerpts.

    See the instructions here: https://www.elegantthemes.com/blog/divi-resources/changing-the-length-of-your-divi-blog-post-excerpts

    However, where the instructions tell you to enter truncate_post( 470 );, you need to replace that with the_excerpt();. Once you do that, you’ll see Relevanssi-generated excerpts.

    Thread Starter skigirl1369

    (@skigirl1369)

    Im using visual composer with the theme “The Fox” (not Divi)

    Plugin Author Mikko Saari

    (@msaari)

    Ah, sorry, I don’t know where I got the Divi. But the issue is probably something similar, I just don’t know how to fix it. If you can show me the search results template (search.php), I can take a look, or you can ask the theme support.

    Thread Starter skigirl1369

    (@skigirl1369)

    Thank you. I have a message out to the theme developer.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Shortcodes in search results’ is closed to new replies.