How to Hide Content until Someone ‘Likes’ Your Facebook Fan Page

16 Jan

Hiding content from Facebook users until they ‘Like’ your fan page is a great way to increase the amount of fans following your page by giving users extra incentive to actually want to ‘Like’ your fan page. By utilizing fb:visible-to-connection a handy piece of built in FBML code we will be able to easily hide content from users until they ‘Like’ your page and become a fan. While this technique is not new and there are already numerous tutorials around on the subject our approach is different. We have simplified our technique in this tutorial to help alleviate some of the confusion we noticed from other tutorials. We have also solved a major issue for page admin’s who cannot see the actual fan content while logged in, however you still must log out in order to test the non-fan content.

PLEASE NOTE: The tutorial below is for FBML only! To learn how to accomplish this for an iFrame, please check out our Fan Gate Reveal Tab Iframe version here:

Step 1: Building the Fan Content DIV

The first step is to build the DIV which will house all of your content that will be visible to your Facebook fans. In order for the non-fan content DIV to be able to cover up the fan content DIV when a user hasn’t ‘Liked’ your fan page a specific height must be used, this same height will also be used on the non-fan content DIV in Step 2. Also please note the usage of the attribute z-index; this will be addressed in Step 2.


1 .fan_content{
2 width: 520px;
3 height: 500px;
4 float: left;
5 position: relative;
6 background: #ccc;
7 z-index: 1;
8 }


1 <div class="fan_content">Fan Content Goes Here</div>

Step 2: Building the Non-Fan Content DIV

The next step is to build the non-fan content DIV which will house your image or content telling users in whatever way you choose to ‘Like’ your fan page in order to view the hidden content. In Step 1 we set a specific height for our fan content DIV, we are going to use that same height on our non-fan content DIV in order to make sure we cover up all of the content we want to hide from non-fans. We will also use that same height and apply it as a negative number to our margin-top attribute; this will ensure that our non-fan content DIV covers up our content DIV exactly pixel for pixel. Remember in Step 1 we set our z-index attribute to 1, well on our non-fan content DIV we will set the z-index attribute to 0, this will ensure that when you are logged in as admin you will always see the fan content instead of the non-fan content.


1 .non_fan_content{
2 width: 520px;
3 height: 500px;
4 float: left;
5 position: relative;
6 background: #666;
7 margin-top: -500px;
8 z-index: 0;
9 }


1 <div class="non_fan_content">Non-Fan Content Goes Here</div>

Step 3: Wrapping the Content DIVs

The next step is a relatively simple step and is just a coding preference to keep all of the content contained, it is totally optional. Apply the following CSS and wrap your previous two DIVs with the wrapper DIV. The benefit in doing this step is that by setting the overflow attribute to hidden we guarantee that all of our content stays contained within the wrapper DIV. Please note that if you’ve used any other wrapper DIVs in your code please make sure that none of the code conflicts.


1 .wrapper{
2 width: 100%;
3 float: left;
4 position: relative;
5 overflow: hidden;
6 }


1 <div class=”wrapper”>
2    <div class="fan_content">Fan Content Goes Here</div>
3   <div class="non_fan_content">Non-Fan Content Goes Here</div>
4 </div>

Step 4: Making it Work with FBML’s fb:visible-to-connection

The last and final step is to make it all work using FBML’s fb:visible-to-connection code to show content depending on whether or not the Facebook user has ‘Liked’ your fan page. Basically all that needs to be done is wrap both of your content DIVs inside of the fb:visible-to-connection tag and then wrap all of your non-fan content inside of the fb:else tag. After you have your final code upload it to your Static FBML tab and test it while both logged in and logged out, while logged in your fan content should be visible and while logged out your non-fan content should be visible. It’s that simple!

1 <div class="wrapper">
2   <fb:visible-to-connection>
3     <div class="fan_content">Fan Content Goes Here</div>
4   <fb:else>
5     <div class="non_fan_content">Non-Fan Content Goes Here</div>
6   </fb:else>
7   </fb:visible-to-connection>
8 </div>

Complete Code


01 .wrapper{
02 width: 100%;
03 float: left;
04 position: relative;
05 overflow: hidden;
06 }
07 .fan_content{
08 width: 520px;
09 height: 500px;
10 float: left;
11 position: relative;
12 background: #ccc;
13 z-index: 9;
14 }
15 .non_fan_content{
16 width: 520px;
17 height: 500px;
18 float: left;
19 position: relative;
20 background: #666;
21 margin-top: -500px;
22 z-index: 0;
23 }


1 <div class="wrapper">
2   <fb:visible-to-connection>
3     <div class="fan_content">Fan Content Goes Here</div>
4   <fb:else>
5     <div class="non_fan_content">Non-Fan Content Goes Here</div>
6   </fb:else>
7   </fb:visible-to-connection>
8 </div>

Please Note:

This tutorial will only work for Facebook Static FBML.


If you are having problems getting this tutorial to work please reread the tutorial and try again, if you still can not get it to work please leave us a comment below and we will respond as soon as possible.

Leave a comment

Posted by on January 16, 2012 in Facebook


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: