How to Exclude CookieYes Script from SG Optimizer Plugin

Last updated on August 29, 2024

Overview

Using CookieYes and SiteGround Optimizer (SG Optimizer) together on your WordPress website might lead to compatibility issues that affect the proper functioning of CookieYes. Specifically, the SG Optimizer’s caching and optimisation function may interact with CookieYes’s script, resulting in unexpected behaviour such as an empty or error-prone cookie banner. To prevent this, exclude the CookieYes script from SG Optimizer’s optimization. By doing so, you ensure the proper functionality of CookieYes while still having the benefits of using SG Optimizer. 

Steps to exclude CookieYes script from the SiteGround Optimizer plugin

Step 1: Access the Theme File Editor

Log in to your WordPress admin dashboard and navigate to Appearance > Theme File Editor.

Step 2: Locate Theme Functions File

In the list of theme files on the right, find and click on Theme Functions (functions.php).

Theme Function in file editor
Step 3: Add the Exclusion Code

Scroll down to the code editor section and add the following snippet at the end of the file:

add_filter( 'sgo_javascript_combine_exclude_ids', 'js_sgo_javascript_combine_exclude_ids' );

function js_sgo_javascript_combine_exclude_ids( $exclude_list ) {
    $exclude_list[] = 'cookie-law-info-gcm-var-js';
    $exclude_list[] = 'cookie-law-info-gcm-js';
    $exclude_list[] = 'cookie-law-info-wca';
    $exclude_list[] = 'cookieyes-banner';
    $exclude_list[] = 'cookieyes';
    return $exclude_list;
}
Exclusion code to optimize CookieYes script
Step 4: Save Your Changes and Clear the Cache

Click the Update File button to save the changes. And then, clear the cache of your website to reflect the update. After completing these steps, the cookie banner should no longer be empty or show errors.

Conclusion

By excluding the CookieYes script from SG Optimizer’s optimization process, you can resolve compatibility issues while maintaining the benefits of both plugins. This solution ensures that your website’s cookie consent management functions correctly without compromising on performance optimization.

Have more questions?

Reach out to us and we'll answer them.

Contact us