Splash Screen displaying on all website pages

I have an issue with a splash screen on one of my websites, it displays as I want it to but is popping up on every page when it needs to just pop up once on the homepage
The code below is what we have in our php file currently - Is there anything we can add to the below restrict the pages to just the homepage?
See code below:

	$date_valid = strtotime('14-10-2021') < time() && time() < strtotime('14-10-2022');
	$show_splash = true;

  setcookie( 'cookies_set', true, time() + 86400*30, '/', cmw.net', true);

  if(isset($_COOKIE['cookies_set']) && !isset($_COOKIE['showSplash'])) {
      setcookie( 'showSplash', true, time() + 86400, '/', 'cmw.net', true);
      $show_splash = true;
<?php if($show_splash && $date_valid): ?>
<div id="splashOverlay" class="splash-overlay" onclick="closeSplash()">
  <div class="splash-container">
  	<div class="splash-close" onclick="closeSplash()">
  		<i class="fa fa-times-circle" style="color: #000;font-size: 38px;"></i>
  	<!-- /43271057/cmw_interstitial_640x480 -->
		<div id="div-gpt-ad-1411564579020-0"><script type="text/javascript"> googletag.cmd.push(function() { googletag.display('div-gpt-ad-1411564579020-0'); });
<?php endif; ?>

<script type="text/javascript">
 function closeSplash() {
 	document.getElementById("splashOverlay").style.display = "none";

Thanks in advance :slight_smile:

The cookie code has nothing to do with WHERE you make the modal/pop-up happen.

If you only want a user to see it ONCE (regardless of page) you set the cookie immediately…so other pages detect and will not show.

That being said… this code should ONLY be executed in the HOME page… or (depending on site set-up)… the header file that detects what content/page it is rendering.

Sponsor our Newsletter | Privacy Policy | Terms of Service