How to Conditionally Hide the Cookie Notice on Specific Pages
Content
One of the most common questions from users of the 'Cookie Notice & Compliance for GDPR / CCPA' plugin is how to prevent the banner from appearing on certain pages. This is often needed for pages like a Privacy Policy, a login page, an internal webview, or a kiosk mode display where the notice is unnecessary or disruptive to the user experience.
Why This Happens
By default, the plugin is designed to display the cookie consent banner site-wide to ensure compliance. The plugin's core functionality does not include a built-in, user-friendly interface for excluding specific pages or post types, which leads users to seek alternative methods for conditional display.
Common Solutions
1. Using the Conditional Display Setting (Limited)
Some versions of the plugin may offer a basic 'Conditional Display' option within its settings. This typically allows you to select a single page, often intended for a Privacy Policy, where the banner should be hidden.
Limitation: As seen in the sample threads, this built-in option can sometimes be unreliable, may not work with caching, and often only allows for one page to be specified. It may also not account for multilingual pages where each language has its own Privacy Policy page.
2. Using a Filter Hook (Recommended Method)
The most powerful and reliable method is to use the cn_cookie_notice_output filter hook provided by the plugin. This allows for complete programmatic control over when the notice is displayed.
Example 1: Hiding the notice on a specific page by ID
function my_hide_cookie_notice( $output ) {
// Replace '123' with the ID of your target page
if ( is_page( 123 ) ) {
return '';
}
return $output;
}
add_filter( 'cn_cookie_notice_output', 'my_hide_cookie_notice' );
Example 2: Hiding the notice on multiple pages or conditions
function my_hide_cookie_notice( $output ) {
// Hide on pages with these IDs
if ( is_page( array( 123, 456, 789 ) ) ) {
return '';
}
// Or hide on a custom post type
if ( is_singular( 'my_custom_post_type' ) ) {
return '';
}
// Or hide on the login page
if ( is_login_page() ) { // Note: You may need to define this condition
return '';
}
return $output;
}
add_filter( 'cn_cookie_notice_output', 'my_hide_cookie_notice' );
How to implement this code: You should add this code to your theme's functions.php file or, preferably, use a code snippets plugin to manage custom functions. Always clear any active cache on your site (plugin, server, or CDN like Cloudflare) after implementing such changes.
3. For Geolocation-Based Hiding
Many users ask about showing the notice only to visitors from specific regions like the EU. The plugin itself does not handle geolocation. As mentioned in the threads, this requires a separate plugin like 'Category Country Aware' (CCA) which can integrate with Cookie Notice to restrict its display based on the user's country.
Troubleshooting Tips
- Caching: If your conditional rules are not taking effect, the most common culprit is a caching system. Purge all levels of cache (plugin, server, CDN).
- Javascript Conflicts: In one thread, a user's 'Dismiss notice' button was broken due to a Javascript error. If your notice behaves strangely, check your browser's console for errors.
- Check the Page ID: Ensure you are using the correct page ID in your conditional function. The ID in the WordPress admin may differ from what you expect.
By using the cn_cookie_notice_output filter, you gain fine-grained control to hide the cookie notice on any page or under any condition you can define with WordPress conditional tags.
Related Support Threads Support
-
Have it NOT Showup on specific pages / Posts!https://wordpress.org/support/topic/have-it-not-showup-on-specific-pages-posts/
-
EU settings onlyhttps://wordpress.org/support/topic/eu-settings-only/
-
Please provide option to hide notice on specified pageshttps://wordpress.org/support/topic/please-provide-option-to-hide-notice-on-specified-pages/
-
remove based on languagehttps://wordpress.org/support/topic/remove-based-on-language/
-
Banner cookie su pagina loginhttps://wordpress.org/support/topic/banner-cookie-su-pagina-login/
-
Show Notice only on Front Pagehttps://wordpress.org/support/topic/show-notice-only-on-front-page/
-
Notice Reappearing on Each Pagehttps://wordpress.org/support/topic/notice-reappearing-on-each-page/
-
Display Refuse-Button (only) on the privacy policy pagehttps://wordpress.org/support/topic/display-refuse-button-only-on-the-privacy-policy-page/
-
Disable on several pageshttps://wordpress.org/support/topic/disable-on-several-pages/
-
Notice only on certain pages?https://wordpress.org/support/topic/notice-only-on-certain-pages/
-
Limit Based On Locationhttps://wordpress.org/support/topic/limit-based-on-location/
-
How can I disable cookie notice in some case ?https://wordpress.org/support/topic/how-can-i-disable-cookie-notice-in-some-case/
-
Disabling the cookie banner on a pagehttps://wordpress.org/support/topic/disabling-the-cookie-banner-on-a-page/
-
show to users by county but also geolocation?https://wordpress.org/support/topic/show-to-users-by-county-but-also-geolocation/
-
Dont allow cookie..https://wordpress.org/support/topic/dont-allow-cookie-1/
-
Exclude from CPThttps://wordpress.org/support/topic/exclude-from-cpt/
-
Choosing pages notice doesn’t appear onhttps://wordpress.org/support/topic/choosing-pages-notice-doesnt-appear-on/
-
How to show this for only EU Visitors?https://wordpress.org/support/topic/how-to-show-this-for-only-eu-visitors/
-
Cookies notice on html pagehttps://wordpress.org/support/topic/cookies-notice-on-html-page/
-
Hide Pop Up on specific pageshttps://wordpress.org/support/topic/hide-pop-up-on-specific-pages/
-
Block/Remove on certain pageshttps://wordpress.org/support/topic/blockremove-on-certain-pages/
-
How To Exclude Certain Pageshttps://wordpress.org/support/topic/how-to-exclude-certain-pages-6/
-
How can I disable the cookie banner on one page only?https://wordpress.org/support/topic/how-can-i-disable-the-cookie-banner-on-one-page-only-2/
-
Cookie Notice – Want Geo Location or Country IP address logichttps://wordpress.org/support/topic/cookie-notice-want-geo-location-or-country-ip-address-logic/
-
Block/Remove on certain pages (webviews)https://wordpress.org/support/topic/blockremove-on-certain-pages-webviews/
-
Close Cookie Notice closes other popupshttps://wordpress.org/support/topic/close-cookie-notice-closes-other-popups/
-
Hide Cookie Buttonhttps://wordpress.org/support/topic/hide-cookie-button/
-
Hide on specific posts and pageshttps://wordpress.org/support/topic/hide-on-specific-posts-and-pages/
-
Hide consent banner – Multilanguage pagehttps://wordpress.org/support/topic/hide-consent-banner-multilanguage-page/
-
Cookie Notice show permanent if cookies disabled in browser settingshttps://wordpress.org/support/topic/cookie-notice-show-permanent-if-cookies-disabled-in-browser-settings/
-
Turning off without deactivatinghttps://wordpress.org/support/topic/turning-off-without-deactivating/
-
delete cookie noticehttps://wordpress.org/support/topic/delete-cookie-notice/
-
Only load assets when requiredhttps://wordpress.org/support/topic/only-load-assets-when-required/