Cookiebot by Usercentrics

Several of our users have reported that the Cookiebot plugin by Usercentrics blocks FacetWP’s scripts, preventing pages with facets from working correctly if cookies are refused.

At the time of writing, we are not sure why and in which situation this happens, as FacetWP itself does not set any cookies. And (unless you are using a Proximity facet or a Map facet), FacetWP also does not load any third-party scripts that set cookies.

To prevent Cookiebot from blocking FacetWP’s scripts, you could add the data-cookieconsent="ignore" attribute to them, as recommended by Cookiebot documentation:

Prevent FacetWP scripts from being blocked

To prevent Cookiebot from blocking FacetWP’s scripts, add the following script to your (child) theme’s functions.php:

How to use custom PHP code?

PHP code can be added to your (child) theme's functions.php file. Alternatively, you can use the Custom Hooks add-on, or a code snippets plugin. More info

add_filter('facetwp_asset_html', function( $html, $url ) { // Check if it's a <script> tag if ( strpos($html, '<script') !== false ) { // Add the data-cookieconsent attribute $html = str_replace('<script ', '<script data-cookieconsent="ignore" ', $html); } return $html; }, 10, 2);

Using the facetwp_asset_html hook, the script adds the data-cookieconsent="ignore" attribute to all of FacetWP’s JavaScript assets.

Because of the check in line 4 code, the the new attribute is only added to <script> tags, and not to <link> tags (CSS files).

With this hook in place, all of FacetWP’s <script> tags will now look like this:

<script data-cookieconsent="ignore" src="https://domain.com/wp-content/plugins/facetwp/assets/js/dist/front.min.js?ver=x.x.x"></script>

Fix errors on sites without jQuery

Another, possibly related issue being reported is that with Cookiebot’s auto-blocking feature enabled, without the above mentioned data-cookieconsent="ignore" attribute fix, FacetWP’s scripts are being loaded in the wrong way, causing a FWP.toggleOverlay is not defined error (and possibly other errors) in the Console.

Enable FacetWP's Load jQuery setting to prevent errors when using the Cookiebot plugin
Enable FacetWP’s Load jQuery setting to prevent errors when using the Cookiebot plugin

This issue only happens on sites without jQuery. We are looking into why this is happening, because FacetWP does not use or need jQuery.

Several users have reported that enabling jQuery in FacetWP’s settings fixes this issue. Until we find the cause, this is currently the only solution.

See also