Skip to main contentSkip to footer

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, and you should see Relevanssi-generated excerpts in the search results pages.

Divi "Use excerpts" setting
Enable the “Use excerpts when defined” setting to see Relevanssi-generated excerpts.

Avoiding indexing menus

If you have menu blocks inside your posts, Relevanssi will index those menu contents as part of every post with the menu. That’s not very helpful. The solution to this problem is adding a filtering function to remove the menus from the posts. The exact content of the filtering function depends on how your site includes the menus in the post, but here’s an example of a function we used to clean out a bunch of menus from one site:

add_filter( 'relevanssi_post_content', 'rlv_remove_menu', 8 );
add_filter( 'relevanssi_pre_excerpt_content', 'rlv_remove_menu', 8 );
function rlv_remove_menu( $content ) {
    $content = preg_replace( '~\[et_pb_text admin_label="Accounts Menu.*?\[/et_pb_text\]~ims', '', $content );
    $content = preg_replace( '~\[et_pb_text admin_label="Footer Menu.*?\[/et_pb_text\]~ims', '', $content );
    $content = preg_replace( '~\[et_pb_text admin_label="Footer Address.*?\[/et_pb_text\]~ims', '', $content );
    $content = preg_replace( '~\[et_pb_text admin_label="Footer Social.*?\[/et_pb_text\]~ims', '', $content );
    $content = preg_replace( '~\[et_pb_text admin_label="Convenience Menu.*?\[/et_pb_text\]~ims', '', $content );
    return $content;
}

This function will clean all the [et_pb_text] shortcodes and their contents where the label matches one of the menu labels.

It’s crucial to run these filters on priority 8 or earlier because the Relevanssi code that cleans out Divi shortcodes runs on priority 9 on the same relevanssi_post_content and relevanssi_pre_excerpt_content filter hooks.

Indexing Blurbs

The Blurb module has essential information in the shortcode attributes, which Relevanssi, by default, does not index. To include the title attribute for the Blurbs, add this to your site:

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

function rlv_shortcode_attribute( $content ) {
	return preg_replace( '/\[et_pb_blurb.*?title="(.*?)".*?\]/im', '\1 ', $content );
}

Dynamic CSS problems

If you have problems with broken search results pages when Dynamic CSS and Relevanssi custom excerpts are enabled, one fix is to disable Dynamic CSS for search results pages with this snippet:

add_filter( 'et_use_dynamic_css', function() { 
	if ( is_search() ) { 
		return false; 
	}
} );

Your account

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

Search

Popular Resources

Automatic redirects to category archives

While Relevanssi Premium can return taxonomy terms as search results, sometimes sending the searcher directly to the category archive is better. This is especially true for WooCommerce sites, where displaying taxonomy terms in search results pages is complicated. Relevanssi Premium has a redirect feature you can use to redirect searches…

Related Posts:

Comment Section:

86 Comments. Leave new

  • This is close to what I need… I have a Divi page that I want to have show up in search results, but there are sections on that page that have a condition on them to make sure they are only visible if the user is logged in. However, Relevanssi still sees it and can show parts of that hidden info in search results. Is there a way to add a CSS class to a section to hide it from Relevanssi indexing? Or a way to automatically not index content that has conditions like this?

    Reply
  • Hi !
    I’m using divi theme and my first question concerne the index. I would like to do a search on the projects too (page / post And project). I checked this option in parameters but no projects on the result. Is there a tip ?
    Thanks

    Reply
    • Vionnet, is there a post type restriction in the search results? Divi may be restricting the search to just posts and pages. See the Divi settings if there’s a restriction on the post types.

      Reply
  • To anyone having the Divi search module adding unwanted parameters issue…

    I found myself asking the same thing today..

    I got some help from Divi supprt.. here’s what worked for me… ymmv

    Go to your WordPress Dashboard > Divi > Theme Options > Integration > Add code to the of your blog and add the following:
    (function($) { $(document).ready(function() { $(‘.et_pb_module.et_pb_search input[name=”et_pb_searchform_submit”]’).remove(); }); })(jQuery);

    good luck!

    Reply
  • Hey there, I’m running Divi and trying to use the Theme Builder to create a custom search results template to adjust how Relevanssi results show up. Is that possible? Whenever I use the Blog module on that template to “Show posts for current page”, nothing happens it just say’s “no results found.” Is it possible to adjust how the search results page looks?

    Thanks,

    Reply
    • Nolan, that’s how it should work. I know very little about Divi, so I can’t help you with Divi details; all I know is that the Blog module in Divi is compatible with Relevanssi.

      There can be many reasons why it’s not working. First thing is to rule out Relevanssi problems: does the Relevanssi admin search (Dashboard > Admin search) work correctly? If it does, then I would recommend asking about this on Divi support forums – that’d probably be the best way to find people who use Relevanssi with Divi and could help you more here.

      Reply
  • Hi Mikko, Divi seems to be adding some things to the URL of the search results page which makes nothing show up. I just want attachments to show.

    This URL does not work: http://www.igeg.org/?s=economy&et_pb_searchform_submit=et_search_proccess&et_pb_include_posts=yes&et_pb_include_pages=yes

    Whereas manually deleting everything after the search term itself does work, eg: http://www.igeg.org/?s=economy

    Any idea how to safely fix this? I didn’t enable this by directly editing the code so I’d like to know how to fix it without editing the code, if possible

    Reply
    • Richard, it’s those et_pb_include_posts and et_pb_include_pages parameters, which make the search only target posts and pages, which excludes your attachments. The solution is somewhat counterintuitive, but you need to edit the Search module settings and under “Exceptions” enable both “Exclude posts” and “Exclude pages”. Despite the names, this does not exclude anything, but instead makes the search include any post types Relevanssi is set to index.

      However, it seems you also need to remove the et_pb_searchform_submit parameter. I’m not sure why, on my Divi test site that parameter has zero effect on the search. I don’t think it’s possible to remove that parameter from the search without adding code to your theme functions.php or a code snippet, but I suppose you can ask the Divi support about it – if it’s possible, they can tell you how. There may be some post type restriction somewhere, since forcing the post type to attachment makes the search work: http://www.igeg.org/?s=economy&et_pb_searchform_submit=et_search_proasdasda&post_types=attachment

      Reply
  • Mohamed Abd ElHalim
    January 25, 2018 7:08 pm

    Hi, all

    I developed a plugin to Easily Remove Unused, Broken Shortcodes from any theme (Divi, Avada, ..etc) or a plugin.

    Video demo: https://www.youtube.com/watch?v=dXVZ5bSUduc
    The plugin site: https://plugins.jozoor.com/shortcode-cleaner/

    The plugin named ( Shortcode Cleaner )
    which it removes unused, broken shortcodes from WordPress, so you can switch between themes and plugins without worrying and keep your content cleanly and fresh all the time, it is dealing with any theme (Divi, Avada, ..etc) shortcodes that are left when changing themes or plugins.

    I think it will be useful for any site.

    Reply
  • Itamar Megged
    June 12, 2017 7:52 pm

    In VC there’s also the

    shortcode which usualy includes a raw huge line of random characters. These characters are not stripped out with the code provided here, but I’ve modified it a bit so it does. please feel free to use:

    /** strip out all shortcodes + content inbetween `vc_raw_html` tags from search result excerpt **/
    add_filter(‘relevanssi_pre_excerpt_content’, ‘rlv_shortcode_blaster’);
    function rlv_shortcode_blaster($content) {
    $content = preg_replace(‘/[(vc_raw_html).*?].*?[/1] ?/’, ”, $content);
    $content = preg_replace(‘/[.*?]/s’, ”, $content);
    return $content;
    }

    Reply
  • I used this method and it works.. but i also use [stm_post_info] in my post its theme component.
    Can you guide me how i can exactly prevent it from displaying in search too. Thanks

    Reply
    • Nevermind one of your research below helped me understand the logic. It was fixed with this simple tweak addition:

      $content = preg_replace(‘/[/?stm.*?]/’, ”, $content);

      Reply
  • Hello,
    I use the last version of DIVI theme of elegantthemes.com.
    I tried to use your plugin but seems not works fine.
    I saw that when I use the standard search field the url appear:

    http://www.domain.com/?s=personale and the search works fine!

    but If I use the search module of ET the url appear:

    http://www.domain.com/?s=personale&et_pb_searchform_submit=et_search_proccess&et_pb_include_posts=yes&et_pb_include_pages=yes

    and the result is blank!

    Why?

    I have created a functions.php file in /child theme folder but nothing.

    Anyone can help me ?

    regards
    Antonello

    Reply
  • Luisa Sangeeta
    December 8, 2016 11:20 am

    Hello! It totally worked for my excerpts! Thank you very much!
    Another problem I am getting since I installed relevansii, is that the “no result” page from the search has the text all separated in three rows, like in the print screen. All the other pages where I get a “no result” (category pages with no posts for example), are looking normal.

    Like in the second print screen.

    Any idea why?

    https://uploads.disquscdn.com/images/70595651faadbe56d45459756252df144f68c4c4284e28d411acf81a773ba38f.jpg

    https://uploads.disquscdn.com/images/5727870949a6f5aabc055b4ef6f6c86e4ac8d6b37adcf1f144ba8f4f93942ab3.jpg

    Reply
    • You have this in your CSS file, forcing the content to three columns:

      .search #left-area, .archive #left-area {
      -moz-column-count: 3;
      /* column-count: 3; */
      -moz-column-gap: 60px;
      /* column-gap: 60px; */
      }

      Reply
  • Where does this code go for Divi sites?

    Reply
  • Hello Mikko,

    I am using Jupiter Theme from Artbees, and visual Composer.

    What should I write instead of Divi?
    On funcitons.php I added
    “function rlv_trim_divi_shortcodes($content) {

    $content = preg_replace(‘/[/?[vc.*?]/’, ”, $content);
    return $content;
    $content = preg_replace(‘/[/[mk.*?]/’, ”, $content);
    return $content;

    }”

    Reply
    • What kind of shortcodes are you seeing? If you’re seeing [vc_] and [mk_] shortcodes, then that is correct, except you need to remove the first “return $content;”.

      Reply
  • Hello Mikko,

    I am using theKen theme from artbees which is using visual composer. As far as I read so far this might mean trouble. I seem to have similar problems like the rest. Codes like “[/vc_column_inner]
    [/vc_row_inner][/vc_column][/mk_page_section]” showing up in the search results. I did enter the code you posted into the functions.php of my childtheme like below

    function rlv_trim_divi_shortcodes($content) {

    $content = preg_replace(‘/[/?vc.*?]/’, ”, $content);

    return $content;

    }

    I could confirm the filter is running using echo “running filter”; exit(); and then removing it again.

    The text sniplets for searching a search term like “toleranzen” never the less looks like:
    …text_transform=“uppercase“ font_family=“none“]Toleranzen bei Stab und Coil[/mk_fancy_title]

    I did check the boxes on “new user defined search sniplet” and “execute shortcodes in results” in the relevanssi settings.

    Is there anything else I could try to solve this issue?

    Reply
  • Christine Jackson
    October 14, 2016 12:09 am

    Mikko, I tried this (using visual composer). I used the replacement vc as you suggested and this did not work. Furthermore, search results are also showing wordpress short codes (e.x. ) and theme shortodes

    Reply
  • hossein hajipour
    August 17, 2016 3:29 pm

    Thanks a lot for your quick reply. I know the results will remain the same, but the excerpt that will be show with the results may not be related to the search keyboard(s). For example if I search a title of divi text the excerpt will be unrelated to that because we ignore theme. All in all is there any better solution to keep the context of divi modules in the excerpts?

    Reply
  • hossein hajipour
    August 16, 2016 10:15 pm

    The problem of this solution is that all excerpts related to divi (such as title or text) will be ignore in the search results. Is there better solution for this problem? like, interpreting all of divi codes before considering theme as excerpt?

    Reply
    • This solution doesn’t actually affect the search results, only the excerpts.

      Relevanssi expands all the shortcodes when preparing the content for excerpts, but the Divi shortcodes do not work properly and cannot be expanded at that point.

      Reply
  • An if there is more than one code to strip? is the same code?
    Also when some sharing plugins add text in the top of the post how can we strip that to? I am using Massahre and it displays the share count in the excerpt

    Reply
    • Depends on how and where in the process the plugin adds the text. If it happens after Relevanssi is done, then it’s impossible to block from Relevanssi, if it happens before then it’s simple, just use relevanssi_excerpt_content filter to weed it out.

      And yes, you can add multiple preg_replace() lines to clean out multiple tags.

      Reply
  • txspiderman
    July 28, 2016 1:37 am

    I am using the7 theme and get the same results. I added the code to my functions.php and reindexed. I still get the ugly descriptions, ideas?

    Reply
  • Newbie question…. Where should this code be put on Divi ?

    Reply
  • Oops, I didn’t see the last curly bracket so I got my site unreachable until I got it 😀

    Reply
  • This is great – could you please explain where this code is to be placed??

    Reply

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