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)
<?php if(!isset($_COOKIE['no_splash'])) { // Start of the IF statement - if the user does not have a cookie that says whether he/she has visited the splash page, take them to the splash page 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 //.... do page 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.
Below this code you will put your HTML for the splash page.
3) You promise to never create another useless splash page!
Posted in Computers & Internet, Wordpress