The following code snippet allows you to hide the cookie bar created by GDPR Cookie Consent (CCPA Ready) plugin on selected pages of the website or any wildcard URL entry. Simply add the code snippet to the active child theme function.php and enter the slug of the pages in the array() function on which you want to hide the cookie bar.
- Was this article helpful?
- Yes, thanks!Not really
Comments (18)
Drew
May 30, 2023
Hi! How can I make it so it *only* appears on the pages (slugs) I specify?
I tried this but it didn’t work:
function webtoffee_custom_selected_pages($html, $slug) {
$slug_array = array('manage-cookies');
if (!in_array($slug, $slug_array)) {
$html = '';
return $html;
}
// For wild card URL entry
foreach ($slug_array as $slug_ar) {
if (strpos($slug_ar, '*') !== false) {
if (fnmatch($slug_ar, $slug)) {
$html = '';
return $html;
}
}
}
return $html;
}
Hema
June 12, 2023
Hello Drew,
Thanks for reaching out. Kindly reach via customer support for customized code.
Joonas Limberg
June 9, 2021
Huh, I add this to my themes functions.php with my page slug and nothing happens. The page still displays the cookie consent bar.
What is this part about the “active child theme” – does it not work directly on themes functions.php?
Mark
June 10, 2021
Hi Joonas,
The code will work even if added in the theme’s functions.php. Please submit a ticket here with site URL.
Dean Hodges
April 6, 2021
This is to disable and NOT hide the bar as we still need it on the privacy page.
How can you hide for a specific page but still use a shortcode to show the popup?
Mark
April 16, 2021
Hi Dean,
I am afraid currently this is the only filter we have regarding this usage.Sorry to let you down.
Hervé Roche
April 27, 2021
I agree.
Using this or the setting on the cookie link button is problematic.
Users can’t read the privacy page from the link if they don’t agree or decline before.
Or if we hide it on the page, shortcode to change settings in the privacy page (which is the logical page to put them) don’t works.
We need a way to minimize or hide on specific page (like privacy page) without disabling it.
Mark
May 2, 2021
Hi Harve,
We understand your concern and we will do an improvement to the feature in coming update.
Anthony
February 10, 2021
I’m a novice with PHP code so i don’t understand what to write and where to write it to adapt the code to my site.
Please add a short example tutorial
Mark
February 12, 2021
Here is a sample code for pages ‘sample-page’ and ‘shop’.
add_filter('cli_show_cookie_bar_only_on_selected_pages', 'webtoffee_custom_selected_pages', 10, 2);
function webtoffee_custom_selected_pages($html, $slug) {
$slug_array = array('sample-page', 'shop');
if (in_array($slug, $slug_array)) {
$html = '';
return $html;
}
// For wild card URL entry
foreach ($slug_array as $slug_ar) {
if (strpos($slug_ar, '*') !== false) {
if (fnmatch($slug_ar, $slug)) {
$html = '';
return $html;
}
}
}
return $html;
}
samantha
January 8, 2021
how do I make a wildcard for say, a taxonomy or a string within a CPT?
Mark
January 13, 2021
Hi Samantha,
The code already supports wild card entry. Please see the second portion of the code.
Rodrigo Vieira
October 6, 2020
How do I make the bar appear on wp-login?
Mark
November 3, 2020
There is no option to do.
Martin
February 24, 2020
If I use that code snippet I get javascript errors on pages without the cookie bar
TypeError: undefined is not an object (evaluating ‘this.settings.showagain_tab’)
TypeError: undefined is not an object (evaluating ‘textBlock.html().length’)
What do I have to do?
Mark
February 25, 2020
Please submit a ticket in support forum with site details.
Amy
January 16, 2019
Hello,
I’m sorry but it is complicated for me to use the php code.
I know that I have to go to my Editor menu and select the functions.php but I don’t know which slug of page I have to add in order to delete the cookie law text from the error page regarding the post considered as spam.
Could you please help me more to solve this issue. I will add my website url in the field requested.
The issue happens when we clik on an article and someone click on send your message without completing the fields requested.
Thank you.
Mark
January 17, 2019
Hi Amy,
We can help you set it up. Please raise a support ticket here, with your site login information and mention the page that you want to hide the bar from.