Creating a Lightbox Subscription Form in Wordpress
October 22nd, 2007 | Published in category: Wordpress Technical | 1 Comment
We received a lot of emails on how to create our Lightbox subscription form, so we decided to post step-by-step instructions.
Our Lightbox form will do the following:
- Automatically load a subscription form in a lightbox when a specified webpage is called.
- Give the user the choice of signing up for our newsletter, or opting out.
- If the user signs up, we redirect them to a thank you page.
The first step is to download and install the necessary plugins as per their instructions:
CREATE A NEW PAGE TEMPLATE:
When we create the subscription page that will pop-up in the lightbox, we want to remove the header and footer. To do that in Wordpress, we need to create a new page template. We’ll call it: lightbox-subscribe.php
- Copy your themes page template and name the new file: lightbox-subscribe.php
- Remove all references to the header and footer
- Place this code at the very top. This tells Wordpress the name of the template:
- Save the file
/*
Template Name: lightbox-subscribe
*/
?>CREATE A NEW SUBSCRIPTION AND THANK-YOU PAGE:
- Create a new page called “subscribe”
- Enter the following text: “Our mailing list rocks, so subscribe now”
- Make sure to include the Subscribe2 token in the page or you won’t have a form. The token is:
<!--subscribe2-->
- To allow your readers to opt-out of signing in, put this code on the page as well:
<a href="#" onclick="parent.parent.GB_hide();">No Thank you</a>
- On the right side of the Wordpress screen you should see a section called: Page Template. Click on the dropdown and select: “lightbox-subscribe”. That’s the template you just built.
- Click Save
- Create a new page called “thank you”.
- Thank your reader for signing up.
- Place this code in the page:
<a href="#" onclick="parent.parent.GB_hide();">close</a>
- Select the “lightbox-subscribe” page template as described above and click Save.
EDIT THE SUBSCRIBE2 PLUGIN TO REDIRECT TO THE THANK-YOU PAGE
- This part is tricky and dangerous. One wrong move and you’ll have to go back and upload the subscribe2.php file again.
- Got to your plugins, find Subscribe2 and click edit.
- Find the following code:
//set this to not send duplicate emails $this->s2form = $this->confirmation_sent; } else { // they're already subscribed
and change it to:
//set this to not send duplicate emails header("Location:/thank-you"); //$this->s2form = $this->confirmation_sent; } else { // they're already subscribed
4. Click “update file”. At the top of the plugin page Wordpress will either tell you that you were successful or you made a mistake. If you did it correctly, congratulations! If not, overwrite your current subscribe2.php file and start again.
That completes the first major step; creating the Subscription and Thank You pages. Now let’s place them in a lightbox pop-automatically.
We need to create a new page template for triggering the lightbox :
CREATE A NEW PAGE TEMPLATE FOR THE TRIGGER PAGE
- Copy your themes page template and name the new file: lightbox-home.php
- Place this code at the very top. This tells Wordpress the name of the template:
/* Template Name: lightbox-home */ ?> - Place this code right before the footer call and then save the file. This will auto load the page titled “subscribe”:
<script language="javascript"> AJS.AEV(window, 'load', function() { GB_show("Subscribe", "/subscribe"); }); </script>
CREATE YOUR TRIGGER PAGE
- Create a new page called “welcome”
- Enter whatever text you want.
- On the right side of the Wordpress screen under Page Template, click on the dropdown and select: “lightbox-home”. That’s the template you just built.
- Click Save
Now whenever someone visits www.your-site.com/welcome, they will automatically see a lightbox subscribe form.
I would like to thank Hani Musallam for his enormous help with this project.

October 26th, 2007 at 12:07 pm
Really great post! Thank you