How to Create Session Based Splash Page in WordPress

Share This Post

Share on facebook
Share on twitter
Share on linkedin
Share on whatsapp
Fast Hosting as low as $2 per month

Last Updated: June 27, 2020 | Reading Time: < 1 minute

Back in year 2000, splash page used to attract visitor by displaying beautiful graphic on their homepage, most of the websites utilize it. In modern era, splash page considered “useless” as it face a huge SEO issue. 

Case:
I need a splash page to display an announcement, but it should not override my homepage, and just need to show it one at a time, so if the visitor back to homepage for the second time and soon, the splash should not there.

Solution:
Create a session based splash page that store cookie on visitor’s browser, set the expiration value, so the splash will not appear as long as the cookie remain in the browser.

Let us start to create with simple session command, for more information about php session you can read it on PHP Manual.

Start by editing your index.php or home.php, here’s the code example:

// start the session
session_start();

// check if the session already made if not
// includ the splash page
if (!isset($_SESSION['splash_shown'])) {
// Show your splash page / code here
include('splash-page.php');

// Define the session cookie lifetime (second)
// zero means no expiration
session_set_cookie_params(0);

// Add a value to Session Var
$_SESSION['splash_shown'] = 1;
} else {
// If session already exist
// Add your index.php code here
get_template_part('loop','index');
}

Got experience with the same case? or if there’s any good plugin to handle the splash page, let me know.

Please Note: Session usage possibly break under WordPress cache activated. I’ll update you more with this.

2 Responses

Any idea? Fill the comment below

This site uses Akismet to reduce spam. Learn how your comment data is processed.

More To Explore