Exclude div and all its content

Using the wordpress plugin.

We have a div with a sitemap on all pages. <div id="sitemap">...</div>
The content of this div is showing up in all search results.

What we are trying to figure out is how we can exclude this div from the indexing.

I have tried with the algolia_strip_patterns filter to no availability.

Hi there,

So that we may further assist, can you provide the following:

  • live urls with the issue

  • screenshots displaying the problem

  • code snippets using the algolia_strip_patterns filter

  • purpose of the div with id of sitemap


Hi there,

Yes, the url is, http://discoverytravel.worksonline.dk/johan-test/


As you can see I have searched the term “lanka” as in Sri Lanka.
You can see results showing such as, Bali, Cambodia, Mauritius.
And, if you look at the excerpt, they are all the same. This comes from the div I mentioned, sitemap that is on all pages.

Here is an example page, http://discoverytravel.worksonline.dk/rejseforslag/bali-three-ways/

The purpose of the div is to provide inspiration for visitors.

Here is the snippet I am trying to use.

add_filter( 'algolia_strip_patterns', function( $patterns ) {
    $patterns[] = '/^.*.(<div id="sitemap">.*.<div>).*.$/im';

    return $patterns;
} );

Regex is probably not a good way to do it, but maybe there is another way to accomplish this.
maybe there a data-attribute that one can add to an html element?

I know, there is an example using yoast and no-index to prevent posts being indexed. Maybe there is a similar mechanism to prevent certain content on a page being indexed?

Could any of these be an oprtion:

Do you have any input?

@rayrutjes Do you have any input or suggestions?