Closed blorange2 closed 4 months ago
Running into the same issue. Here is how to fix it: https://support.cookiebot.com/hc/en-us/articles/360009063660-Disable-automatic-cookie-blocking-for-a-specific-script @wp-rocket just add this attribute data-cookieconsent="ignore"
@piotrbak hi, I know this is only medium priority but in the interim is there a quick and dirty way for me to add what I need as a temporary fix? Thanks
To get around my issue momentarily I've done the following:
/**
* Returns the lazyload inline script
*
* @param array $args Array of arguments to populate the lazyload script options.
* @return string
*/
public function getLazyloadScript( $args = [] ) {
$defaults = [
'base_url' => '',
'version' => '',
];
$args = wp_parse_args( $args, $defaults );
$min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
/**
* Filters the script tag for the lazyload script
*
* @since 2.2.6
*
* @param $script_tag HTML tag for the lazyload script.
*/
return apply_filters( 'rocket_lazyload_script_tag', '<script data-cookieconsent="ignore" data-no-minify="1" async src="' . $args['base_url'] . $args['version'] . '/lazyload' . $min . '.js"></script>' ); // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript
}
As you can I see I've just added the cookie consent ignore piece to where the script is inserted inside wp-rocket/inc/Dependencies/RocketLazyload/Assets.php
. This is probably not a good solution by any means but it solves my issue for now.
I tried with our latest version of WPR and I can't reproduce it with CookieBot plugin.
@blorange2 can u plz open this admin page
/wp-admin/admin.php?page=cookiebot_debug
and send us the section of --- Cookiebot Information ---
to be able to reproduce it?
If you want to temporary add this data attribute to this script, you can use the following code:
add_filter( 'rocket_lazyload_script_tag', function( $script ){
return str_replace( '<script ', '<script data-cookieconsent="ignore" ', $script );
} );
without changing the code in the plugin core as this will be overwritten with any update.
@engahmeds3ed thank you for the feedback, that's interesting to hear. Please see below thr requested information.
##### Debug Information for https://ZZZ.ZZ generated at 2023-02-14T15:41:23-01:00 #####
WordPress Version: 6.1.1
WordPress Language: en-GB
PHP Version: 8.0.27
MySQL Version: 5.7.38
--- Cookiebot Information ---
Plugin Version: 4.2.4
Cookiebot ID: ZZZZZZZZZZ
Blocking mode: auto
Language:
IAB: Not enabled
CCPA banner for visitors from California: Not enabled
CCPA domain group id:
Add async/defer to banner tag: None
Add async/defer to declaration tag: async
Auto update: Enabled
Hide Cookie Popup: No
Disable Cookiebot in WP Admin: Yes
Enable Cookiebot on front end while logged in: No
List of ignored javascript files:
Banner tag: <script type="text/javascript"
id="Cookiebot"
src="https://consent.cookiebot.com/uc.js"
data-cbid="ZZZ"
data-blockingmode="auto"
></script>
Declaration tag: <script
type="text/javascript"
id="CookieDeclaration"
src="https://consent.cookiebot.com/ZZZZ7/cd.js"
async></script>
GTM tag:
GCM tag: <script data-cookieconsent="ignore">
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag("consent", "default", {
ad_storage: "denied",
analytics_storage: "denied",
functionality_storage: "denied",
personalization_storage: "denied",
security_storage: "granted",
wait_for_update: 500,
});
gtag("set", "ads_data_redaction", true);
gtag("set", "url_passthrough", true);
</script>
--- Activated Cookiebot Addons ---
WP Rocket (statistics)
--- Activated Plugins ---
ACF Content Analysis for Yoast SEO (Version: 3.0.1)
Advanced Custom Fields PRO (Version: 6.0.7)
Classic Editor (Version: 1.6.2)
Custom Image Sizes by DraftPress (Version: 1.2.8)
Custom Post Type UI (Version: 1.13.4)
Yoast Duplicate Post (Version: 4.5)
Header Footer Code Manager (Version: 1.1.32)
Health Check & Troubleshooting (Version: 1.5.1)
Imagify (Version: 2.1)
WPCode Lite (Version: 2.0.4.4)
Ninja Forms - Conditional Logic (Version: 3.1)
Ninja Forms - Multi-Part Forms (Version: 3.0.26)
Ninja Forms - Salesforce CRM (Version: 3.2.0)
Ninja Forms - Layout & Styles (Version: 3.0.29)
Ninja Forms - File Uploads (Version: 3.3.14)
Ninja Forms - Webhooks (Version: 3.0.5)
Ninja Forms (Version: 3.6.16)
Pretty Links (Version: 3.3.1)
Public Post Preview (Version: 2.10.0)
Redirection (Version: 5.3.8)
Regenerate Thumbnails Advanced (Version: 2.4.0)
Safe SVG (Version: 2.0.3)
Secure Admin IP (Version: 2.0)
Simple Custom Post Order (Version: 2.5.6)
Advanced Editor Tools (previously TinyMCE Advanced) (Version: 5.6.0)
Unlist Posts & Pages (Version: 1.1.9)
UpdraftPlus - Backup/Restore (Version: 1.22.24)
Wordfence Security (Version: 7.8.2)
WordPress Importer (Version: 0.8)
Yoast SEO (Version: 20.0)
WP Mail SMTP (Version: 3.7.0)
WP Rocket (Version: 3.12.2.1)
WP Hardening (Version: 1.2.6)
##### Debug Information END #####
Side question: is the filter function an obvious thing, or did I just miss it in the documentation?
Thanks again
Many thanks @blorange2 Kindly notice that I removed some sensitive data as it's public repository :D
Really I'm not sure about if this filter is documented or not but I got it from the code you shared above.
Plz try it and in the mean time I'll try reproducing it from my side.
+1 I am facing the same issue with elementor + wp-rocket, and sadly the filter does not help. Disabling wp-rockets lazyloading makes the images appear again.
This is not something that can be implemented soon. We might reopen this in the future.
Before submitting an issue please check that you’ve completed the following steps:
Describe the bug A clear and concise description of what the bug is.
WordPress Cookie Consent plugin (CookieBot) causes the wp-rocket lazy load script not to run. Wondering if I can locate the script and ignore it as written here -> https://support.cookiebot.com/hc/en-us/articles/360009063660-Disable-automatic-cookie-blocking-for-a-specific-script
To Reproduce Steps to reproduce the behavior:
Expected behavior A clear and concise description of what you expected to happen.
Screenshots If applicable, add screenshots to help explain your problem.
Additional context Add any other context about the problem here.
Backlog Grooming (for WP Media dev team use only)