-
Hi,
We are using cookiebot for cookie control and GDPR etc, and this script needs to be added as the first thing that gets loaded in the header. I am doing so using an element, with a priority of 1, however, I can see it is still not the 1st thing to load.I’ve tried numerous things, and other scripts are still loading first, meaning cookies are being set before consent is granted.
Any ideas how I can ensure the cookiebot script loads before anything else? I read the loading priority can be < 1, however I cannot set this on the front end.
Many Thanks!
-
Hi there,
Try setting the priority to 0.
But if you have other plugins/functions are also inserting content to
wp_head
with priority 0, then there might still be other content on top of it. -
Thanks for your response, Ying and hope you had a lovely Christmas.
I’ve tried zero and something else is nobbling it to load before hand.
Sadly I can’t add < 0 to try that.
-
Thank you! I think it should work even if it’s not the real first to load 🙂
-
Yes, it still loads, but doesn’t capture the cookies set before it loads which is the issue.
-
Alvind
Hi there,
To ensure the script loads first in the header, you can modify the theme’s
header.php
template file.This process requires using a child theme. Copy the
header.php
template file from the parent theme into the child theme and insert the script code into the child theme’sheader.php
file.For reference, you can insert the script above this line:
https://github.com/tomusborne/generatepress/blob/8598ca648c3d34c24975a20473c045a2f1bc2c98/header.php#L16 -
Thanks, Alvind.
Much appreciated.
I have tried this – I’m using Gravity Forms, and they seem to be able to inject their code to be the first in the header – I have not figured out how to get the cookie bot script above it yet – but I have raised a support ticket with them to see what can be done. -
Alvind
No problem — hopefully, they will be able to provide you with the solution!
- You must be logged in to reply to this topic.