php
Back to Snippets
WordPress Cookie Bar Conditional Display
Hide GDPR cookie consent bar on specific pages using wildcard matching.
php
function hide_cookie_bar_on_pages($should_display) {
$excluded_pages = array(
'/checkout*',
'/my-account*',
'/privacy-policy',
);
$current_url = $_SERVER['REQUEST_URI'];
foreach ($excluded_pages as $pattern) {
$regex = str_replace('*', '.*', $pattern);
if (preg_match('#^' . $regex . '$#', $current_url)) {
return false;
}
}
return $should_display;
}
add_filter('gdpr_cookie_consent_should_display', 'hide_cookie_bar_on_pages');