Call our Oxfordshire office : 01295 724568

Join us on facebook Join us on twitter Join us on linkedin Join us on google+

How to collect an email address before giving access to a WordPress page

Wordpress restrict access to page or post

It sounds pretty simple doesn’t it. I just want to collect an email address then redirect a user to a page of content. This makes complete sense. You have invested time and money in producing some premium content so it’s only fair you ask for an email address in exchange, right?

So, in the process of building a web site for an IT solutions client of ours, we needed to do just that. A quick google around for plugins surely would come up with what we needed? Alas no. All the plugins were just to over blown, for example, there are a number of full membership plugins available but really these were a huge sledge hammer to crack a very small nut.

Thinking cap on. Let’s break the problem down (as with all programming and process problems)

First of all we need a form, check, let’s use Gravity Forms. (

When the user submits the form and it is validated, we want them to be re-directed to our page or post.

The page or post needs some way of validating that the user had indeed provided the relevant information.

So, as we decided to use gravity forms, it has two key pieces of functionality :-

1) You can setup up confirmations for when the form is submitted and one of these confirmations can be a re-direct to another URL (page or post)

2) You can pass data to that page via the URL string.

So here’s an example of the form settings that do just that :-

Gravity Forms Redirection Settings

With that done, when the user fills in the form, they will be re-directed to the URL you specified.

BUT what if the user just keys in the URL directly? Well firstly don’t include a link to the page or post, keep it hidden. Then, you need to test to make sure the value has been set in the query string as shown in the screen shot above. The way we did this was to use a wordpress page template that had the follow code in :-

if ($_GET[‘demo’]!=’1′) {

All this says : if the URL variable demo is not equal to 1 re-direct the browser to a new location. Now obviously this is not watertight because anyone technical could access the page/post by just appending the variable to the URL but really for nearly all situations, you’ll find this is a really effective way of grabbing an email address in exchange to view some of your content.

Hope that makes sense and you find it useful.