Skip to content

Instantly share code, notes, and snippets.

@rwkyyy
Created June 17, 2022 10:01
Show Gist options
  • Save rwkyyy/22ac5acc4723cd537cbdb7d02a67e5e0 to your computer and use it in GitHub Desktop.
Save rwkyyy/22ac5acc4723cd537cbdb7d02a67e5e0 to your computer and use it in GitHub Desktop.
DEAD SIMPLE cookie notice (WordPress function)
add_action('wp_footer', 'add_cookie_notice_function');
function add_cookie_notice_function(){
$url = get_privacy_policy_url();
$link = '';
if (get_privacy_policy_url() != ''){
$link = '<a style="font-size: small; text-align: right" rel="nofollow" href="' . $url . '">Detalii</a>';
}
echo '<p id="cookie-notice">Lorem ipsum sil dolor. <br><button onclick="acceptCookie();">OK</button> ' . $link. ' </p>';
echo '<script>function acceptCookie(){document.cookie="cookieaccepted=1; expires=Thu, 18 Dec 2030 12:00:00 UTC; path=/",document.getElementById("cookie-notice").style.visibility="hidden"}document.cookie.indexOf("cookieaccepted")<0&&(document.getElementById("cookie-notice").style.visibility="visible");</script>';
echo '<style>#cookie-notice{color:inherit;font-family:inherit;background:#fff;padding:20px;position:fixed;bottom:10px;left:10px;width:100%;max-width:300px;box-shadow:0 10px 20px rgba(0,0,0,.2);border-radius:5px;margin:0;visibility:hidden;z-index:1000000;box-sizing:border-box}#cookie-notice button{font-weight: 700;font-size: 100%;background:#ef1c25;border:0;padding:10px;margin-top:10px;width:100%;cursor:pointer;color:#fff}#cookie-notice a{color:inherit;font-weight:bold;text-decoration:underline}@media only screen and (max-width:600px){#cookie-notice{max-width:100%;bottom:0;left:0;border-radius:0}}</style>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment