Complianz Privacy Suite

Hide the cookiebanner on certain pages

Aert Hulsebos

Aert Hulsebos

Categories

Popular articles

Creating the Legal Hub

Have you seen our new Legal Hub? If not, have a look before reading this instruction article. We created the legal hub to centralize our

Read More

Placeholders for iFrames

From 4.6.11 onwards, you can also use consent shortcode wrappers. An instruction can be found here. You’re able to block iFrames with Complianz with the

Read More
Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn

Some use cases might be better off by excluding the cookie banner on certain pages. These use cases should be considered individually. With update 4.7.1 we added a setting using a meta-box, which makes it very simple to hide the cookiebanner from a specific page. If you want to exclude a larger number of pages, you can also use a WordPress filter, which we will explain below as well.

Exclude pages or posts using the Gutenberg editor

  1. Navigate to the page or post where you want to hide the cookiebanner.
  2. Make sure you open the settings tab, using the button on the top-right of your screen.
  3. Find the cookiebanner tab and click ‘hide cookiebanner on this page’.

Exclude pages or posts using the Classic editor

  1. Navigate to the page or post where you want to hide the cookiebanner.
  2. Find the cookiebanner metabox and click ‘hide cookiebanner on this page’.

The Filter – Exclude a single page

You can exclude the banner by using a filter in your functions.php, but we would suggest using an MU Plugin.

/**
 * Filter post types for cookiewarning
 * It's too early to use global $post or url_to_postid(), so we do a simple text comparison
 * @param $cookiewarning_required
 * @return bool
 * props to @playnary on wordpress.org
 */
function cmplz_my_filter_site_needs_cookiewarning( $cookiewarning_required) {

	$url = (is_ssl() ? "https" : "http") . "://" .$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI];
	if ( strpos($url, 'https://yoursite.com/page') !== FALSE ) { 
		$cookiewarning_required = false;
	}
	return $cookiewarning_required;
}
add_filter( 'cmplz_site_needs_cookiewarning', 'cmplz_my_filter_site_needs_cookiewarning' );

Excluding multiple pages

Needless to say, it might not be a good idea to exclude the cookie banner from multiple pages from a compliance perspective. Though if this is desirable in your situation, you can filter on post ID’s.

Finding the postID which corresponds to your page, post any custom post type.

When editing a page or post, you will find the postID in the domain field of your browser. In this case I’m editing this post with the following URL in my domain field:

https://domain/wp-admin/post.php?post=241441&action=edit

In this case my postID = 241441

For multiple postID’s the filter will look like this:

add_filter('cmplz_site_needs_cookiewarning', 'my_filter_site_needs_cookiewarning');
    function my_filter_site_needs_cookiewarning($cookiewarning_required){
        global $post;
if ($post->ID==241441 || $post->ID==1 || $post->ID==2) $cookiewarning_required=false;
return $cookiewarning_required;
}

Recent articles

Subscribe