How to Make a Popup Execute Once per Session in Wordpress

Check out my other posts and tutorials on Web Development!

Start Session

First, you’ll want to register your session by placing the following in your functions.php file.

/************* Start Session For Popup *****************/

add_action('init', 'register_my_session');

function register_my_session() {
    if( !session_id() ) {

Create Popup

Here we’ll ensure our popup only loads once per session by incrementing our ‘popup’ session variable. Include your popup markup and javascript within the following:

<?php if (!isset($_SESSION['popup'])) { 
    $_SESSION['popup'] = '0'; ?>

    <!-- Enter Popup Here -->

<?php } $_SESSION['popup']++; ?>

Leave a Reply

Contact Us


Subscribe to our blog to receive latest news and tutorials on Web Design, Development, SEO, and more!