Skip to content

Instantly share code, notes, and snippets.

@eclarrrk
Created January 13, 2021 19:45
Show Gist options
  • Save eclarrrk/4638f1215f4173c005d6f99c3755ee6d to your computer and use it in GitHub Desktop.
Save eclarrrk/4638f1215f4173c005d6f99c3755ee6d to your computer and use it in GitHub Desktop.
Creating a lightweight dismissible banner on a PHP site
<?php
$cookie_name = "banner";
if(!isset($_COOKIE[$cookie_name])) :
?>
<div class="banner">
<!-- your content -->
<button onclick="alertClose()" aria-label="Close">
<span role="presentation">&#10005;</span>
</button>
</div>
<script>
function alertClose() {
document.cookie = "<?php echo $cookie_name; ?>";
document.getElementById("banner").style.display = "none";
}
</script>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment