How to Make the Landing Page Plugin a Gateway

You have probably seen or heard of having a landing page that is served to your visitors when they first arrive on your site. The landing page would be served to them no matter what page of your site they were going to. The visitor would have the option to signup for your email list or skip the page. Once they made their decision, either to signup or skip, they would not see the landing page again for a certain time period; maybe never.

When I first created the Ultimate Landing Page Advanced Plugin, I thought this functionality should be in a separate plugin. I now realize it should be part of our landing page plugin. We will be adding this functionality in the near future.

Some users have asked how they can manually code the plugin to make it a gateway. What follows is one way to modify the plugin’s code to make it a gateway. This code has not been thoroughly tested and we offer no support for any custom modifications you make to the plugin. With that said, here is how you might make the landing page plugin a gateway.

Adding the Cookie to the Landing Page

The plugin provides a Custom Code box to place custom css and javascript for each individual landing page.  You need to have a way for the system to know if a visitor has seen the landing page already.  One way to do this is to set a cookie via javascript. You also could set the cookie in .php, but that is beyond this example. The following was taken from and modified.

function setCookie(c_name,value,exdays)
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;

function getCookie(c_name)
var c_value = document.cookie;
var c_start = c_value.indexOf(” ” + c_name + “=”);
if (c_start == -1)
c_start = c_value.indexOf(c_name + “=”);
if (c_start == -1)
c_value = null;
c_start = c_value.indexOf(“=”, c_start) + 1;
var c_end = c_value.indexOf(“;”, c_start);
if (c_end == -1)
c_end = c_value.length;
c_value = unescape(c_value.substring(c_start,c_end));
return c_value;

function checkCookie()
var mycookie=getCookie(“mycookie”);
if (mycookie ==null && mycookie ==””)
setCookie(“mycookie “,”gatewaypostid”,365);

The code above is exactly the same as the code on w3schools website, except I changed the checkCookie() function to only check for the existence of a cookie and create a new one if it doesn’t exist. You can read more about how these functions works at

Basically, all you need to do on your landing page is put the above code inside a script tag, change the second paramater of setCookie to the post id of the landing page you want to use as the gateway page, and then call checkCookie() when the page is loaded.

First, you can get your landing pages post id by doing a preview of the page and getting the value of preview_id from the url in the address bar.

Second, you need to call checkCookie() when the page is loaded using window.onload. Window.onload is already called within the plugins template. If you directly set window.onload, you will override the templates call to window.onload. The best way I have seen to handle this is to use an auxillary method to manage each call to window.onload. This will keep you from overriding the previous calls to window.onload.

function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {


This code was taken from I added the call, addLoadEvent(checkCookie), to show how you would call checkCookie().

Capturing the Cookie and Serving the Landing Page

The best place to handle the cookie and decide if you want to serve a landing page as a gateway page is in the main .php, ultimate-landing-page-advanced.php. The following code would go inside the function ulpa_template_redirect; right after $ulpa_post_id is set. You also will have to modify some of the existing code to use a boolean variable.

$gatewayPostId = '1234';
$passThrough = false;
if($_COOKIE["mycookie"] != $gatewayPostId ) {
$ulpa_post_id = $gatewayPostId ;
$isGoGateway = true;
if(!$isGoGateway ){

// If the post type is set and is campaign…
if (isset($wp->query_vars["post_type"]) || $isGoGateway ) {
if ($wp->query_vars["post_type"] == "landingpage" || $isGoGateway )
// Then use the campaign-template.php file from this plugin directory
include WP_PLUGIN_DIR.'/ultimate-landing-page-advanced/templates/template2.php';

The code above assumes you have set your cookie like so, setCookie("mycookie ", "1234",365);. If the cookie has not been set, then $ulpa_post_id will be set to $gatewayPostId and $isGoGateway = true. This will cause the plugin to skip the coming soon and homepage checks and will also cause the landing page template to be loaded even though the post type is not set to landing page. Obviously, you can set this up differently. You may want to do the coming soon check before the cookie check.

Skip This Link and After Sign Up Destination

To place a Skip This link on the page, you would have to remember the original destination the user was going to before you served the gateway page. You also need to maintain this value to send the user to the page they were headed to before they signed up. You could store this value in a cookie and check it once the user has taken the appropriate action.

A Complex Problem That Needs a Well Thought Out Solution

The gateway functionality is something many want to see in the landing page plugin. We realize that this will be a good addition to the already great features the Ultimate Landing Page Advanced contains. We also realize that adding the gateway functionality is a complex problem because of the many possible scenarios. We are working on a solution that we hope will be useful to you and easy to use. Keep watching for updates.

Posted in Build Email List, Landing Pages, Tutorial