Warning: Creating default object from empty value in /home/jared/public_html/wp-content/themes/canvas/functions/admin-hooks.php on line 160

Archive | Wordpress RSS feed for this section

Forcing a splash page redirect one time with wordpress, php and cookies

I hate splash pages and never ever suggest using one to any of my web development clients. After all, it just delays the user from getting to what they are looking for – your content. Unfortunately sometimes you get a client that doesn’t listen to your recommendations, even when supported with tons of supporting articles against splash pages like these…

Sink the Splash Pages
Splash Pages: Bad for Usability, Bad for SEO
Splash Pages: Do we really need them?

So if you’re building a website with WordPress and you have a client that despite the horrible idea, demands a splash page, I have a solution for you.

1) Edit header.php (inside your theme folder), adding this to the top

This code checks to see if the cookie “no_splash” is set. If the user hasn’t seen the splash page before, they’ll be redirected to the splash page… splash_page.php (which we create in step 2)

// if the user doesn't have a cookie set, take them to the splash page
if(!isset($_COOKIE['no_splash'])) { 
header('Location:http://www.yoururlhere.com/splash_page.php'); // Redirect code
} else { 
// But... if they do have the cookie (they have been on the splash page), just serve the page as normal
//.... place your page content here

2) Create a file called splash_page.php and put it in your site root

At the top of the file we need to add the code to create the cookie, so that next time they come to the site they don’t see this horrible splash page.

// Set the expiration time to 1 day - 60 seconds * 60 minutes * 24 hours * 1 day
// You can change the (1) to any number of days you like
$expire = time() + 60*60*24*1;  

// set the cookie using the above expiration time
setcookie("no_splash", "1", $expire);  

// Your splash page content goes here


Below this code you will put your HTML for the splash page.

3) You promise to never create another useless splash page!


Comments { 3 }