If you want to show content to your fans, and require that a visitor to your Fan Page become a fan in order to view the content, here's a nice bit of FBML to render content on your Facebook Fan Page only to fans. Easy as pie....
NOTE: It is easy to get confused about whether or not this working when you're testing. Remember, if you're an admin of the Fan Page you're using this FBML in, and you're logged in, you will see the content whether or not you're actually a fan of the Page. People get confused about this and think the tags aren't working.
ALSO NOTE: If you follow the below instructions and it's not working, try removing the <fb:fbml version="1.1"> </fb:fbml> tags. I don't believe this is necessary now.
FINALLY: If you want to copy and paste my code, MAKE SURE you convert all quotes to plain-text (straight up and down) quotes! Otherwise, your code will not work!
Content for Fans Only
First, on your Static FBML page, begin with the following:
<fb:fbml version=”1.1″>
Wrap the content you want to hide from non-fans within these tags:
<fb:visible-to-connection></fb:visible-to-connection>
Then end your page with:
</fb:fbml>
And that's it! The content contained between <fb:visible-to-connection> and </fb:visible-to-connection> will be visible to fans only.
How to Show Different Content to Fans and non-Fans
<fb:fbml version="1.1">
<fb:visible-to-connection>
Fans will see this content.
<fb:else>Non-fans will see this content.</fb:else>
</fb:visible-to-connection>
</fb:fbml>
Removing the Space above the Non-Fan Content
Originally, I had proposed using negative margins to make sure the non-fan content isn't pushed down the page by the invisible fans-only content. (Facebook hides the fans-only content using the "visibility: hidden" CSS which hides the content but reserves the space it would take were it visible.)
However, an alternate and perhaps easier method to remove the fans-only content space is to use "position: absolute" CSS which takes the non-fan content out of the document flow (See this article on using the CSS position element) and positions it relative to its containing element (usually a DIV).
In the following example, I have given the containing DIV the ID "wrapper" and used CSS to style it "position: relative". Then the non-fans content is in the DIV with the ID "non-fans" and is "position: absolute" and is set to be flush against the left and top margins of the "wrapper" DIV:
The code in the FBML box:
<div id="wrapper">
<fb:visible-to-connection>
FANS-ONLY CONTENT
<fb:else>
<div id="non-fans">CONTENT FOR NON-FANS</div>
</fb:else>
</fb:visible-to-connection>
</div>
The CSS:
#wrapper {
width:520px;
margin:0 auto; border:0; padding:0;
position:relative;
}
#non-fans {
width:520px;
position:absolute; top:0; left:0;
}
When using the "position:absolute" in CSS the crucial thing to remember is that the element you're positioning absolute will be positioned RELATIVE to the element in which it's contained.
Many folks complain that before a user becomes a fan, and the "non-fan" content is displayed, the "fans-only" content still takes up the space it would if it were being displayed. To fix this, put paragraph tags (<p> ... </p>) around the image or the text for the non-fan content, and set a negative margin on the paragraph tag equal to the height of the fans-only content.
In the example below, the fans-only content is 100px tall:
<fb:else><p style="margin-top:-100px;"><img src="[IMAGE URL]"></p></fb:else>
OR
<fb:else><p style="margin-top:-100px;">Text content for fans only</p>
If your fans-only image is bigger than your non-fans image, and you find that your image is getting cut off:
Surround the entire <fb:visible-to-connection> ... </fb:visible-to-connect> with a <div> tag that includes a style setting the height to the height of the tallest image (600 pixels in the below example):
<div style="height:600px;">
<fb:visible-to-connection>
[content]
</fb:visible-to-connection>
</div>
Troubleshooting
If you aren't having success implementing this code, it is most likely due to one of the issues described below. PLEASE carefully read this post and the troubleshooting tips below before asking questions via the comments.
- IF YOU SEE BOTH FANS-ONLY & NON-FANS CONTENT: To test whether you've implemented this feature correctly, you MUST NOT be logged in as an admin for the page you're adding this to, or you'll see both the content for fans and for non-fans. The best way to test is to create a user profile for testing and log in as that user. You can then "Like" the page and "un-Like" the page to test the display of content. To "unlike" a page, click on the Wall tab for the page and at the bottom of the left column you'll see an "Unlike" link. Click that to unlike the page;
- NO "CURLY" OR "FANCY" FORMATTED QUOTES: Your quotes, whether single or double — and ALL your code — MUST be plain-text. If your quotes aren't straight up and down, then they're formatted quotes and should be fixed or your code will NOT work;
- MATCHING QUOTES: Make sure quotes around values are both the same, either single or double, but they have to match!
- HEIGHT SETTINGS: My fix for the extra space above the non-fan content uses an example height. Make sure you set the height value and the "margin-top" negative values for your individual case.
- TEST YOUR URLS: If you can't access the URL for an image or file directly in your browser, it won't work in your code. Make sure your URLs are correct;
- URLS must be properly formed: After the domain name ("TLD"), URLs are CASE SENSITIVE. They should also contain NO SPACES or, as mentioned above, no specially formatted characters.
Testing your Show/Hide Code
It's important to remember that if you're logged in to Facebook as the user who is the Page admin, you will see both the fans-only and non-fans content.
To properly test your code:
- Set up a new Facebook personal profile, to be used just for testing purposes;
- Log in the Facebook as that new test user and view your Page;
- If you see the "Like" button at the top, then you're not yet a fan (duh!);
- Assuming you're not yet a fan, you should see the content of <fb:else>;
- Click the "Like" button; you should then see the fans-only content and the non-fan content will be invisible;
If you need to do tweaking to the code and re-testing, you'll have to log out as the test user and log back in as the admin to edit the Static FBML.
TIP: Open, say, Firefox and be logged in there as the page admin, and do your testing in a different browser (Internet Explorer or Safari) logged in as the test user. Then you can just switch between browsers to edit and test.
To "Unlike" a Page you've Liked, click on the Wall tab and scroll down to the last links in the left column. You'll see the "Unlike" link:

So you can toggle back and forth between being and fan and not being a fan to test your code.
Other Resources
Facebook Developer Wiki - fb:visible-to-connection



#1 by R0meo - August 21st, 2010 at 06:40
How to NOT show facebook fan page WALL and any other info of the fan page while user is non-fan
any suggestions?
#2 by timware - August 21st, 2010 at 07:28
No way that I'm aware of. How would someone become a fan if they couldn't see anything on your Page? No, you can't hide the Wall tab by any means.
#3 by Razu Kc - August 27th, 2010 at 13:45
Do you know some way to hide the entire left portion of the fan page? Those include people who like the page, other info, links, notes etc. I wan to want to add a Static FBML page, of greater width and its only possible if i could somehow not show the left portion.
#4 by timware - August 27th, 2010 at 14:22
No way, man.
#5 by Pooja Gandhi - August 30th, 2010 at 10:59
Is it possible to hide the photos in albums from non fans
#6 by Carolyn K. - August 30th, 2010 at 12:00
Works like a charm, thank you so much! We had an image to display to fans only, and some text for non-fans encouraging them like us. Thank you for the directions, they were perfect
#7 by Jeremy Lockhart - August 30th, 2010 at 15:43
Still having issues using CSS to position the 2 div's absolutely. I had to resort to using a background image on the div for non-fan content and then putting my fan content over top of it covering it.
#8 by D Webb - August 30th, 2010 at 18:07
Jeremy - thanks for the tip. I was getting the divs to work correctly in FF but IE was still creating the empty space at the top of the page. I used Jeremy's suggestion of a background image, which worked fine but disallowed the use of any complex content.
#9 by timware - August 31st, 2010 at 01:24
The key thing in using absolute positioning to account for the fan-only content space is to MAKE SURE that the DIV that contains the absolute-positioned DIV is set to "position: relative". Then the absolute-positioned DIV will be positioned relative to that containing DIV using the top/bottom and left/right parameters.
#10 by Katie Bolson - September 1st, 2010 at 13:14
Here's the code I'm trying to use for having non-fans see one image, and fans see another image. Problem is, when I have a 3rd party person(non admin) try it, they see both the non-fan image and the image for just fans. Is there a way to make it so that the person sees 1 image before they are a fan, and then just the 2nd image after? I've tried a bunch of variations but I feel like I'm missing something!
Thanks!!
Here's my code
<img width="520" src="http://farm5.static.flickr.com/4102/4948756057_2486809f4b_z.jpg">
<fb:visible-to-connection>
<img width="520" src="http://farm5.static.flickr.com/4149/4948756177_bceed2267c_b.jpg">
</fb:visible-to-connection>
#11 by timware - September 1st, 2010 at 14:14
Katie, You should read this tutorial more closely. It should be obvious what you're doing wrong here.
#12 by Matthew Martindale - September 1st, 2010 at 20:35
This worked for me and might be a simpler route. Thanks to this article, my mind was put on the right track to come up with my version of the solution.
<fb:visible-to-connection>
<style type="text/css">.fancontent{display:block}</style>
<fb:else>
<style type="text/css">.fancontent{display:none}</style>
</fb:else>
</fb:visible-to-connection>
#13 by Matthew Martindale - September 1st, 2010 at 20:37
This code is, of course, followed by the actual content:
<div class="fancontent">Imagine content here...</div>
#14 by timware - September 2nd, 2010 at 09:27
Matthew: Can you provide the URL where this worked, as well as the browser and platform (Mac or Windows)? I couldn't get your "solution" to work in FF or Safari on Mac, or IE 8 on the PC, at which point I stopped testing.
Even if it did work somewhere, I would not advise using inlined <style> tags at all on Static FBML tabs.
A slight modification to your approach that would work is just inlining the styles within the HTML tags: <div style="display:block">, for example.
#15 by Matthew Martindale - September 2nd, 2010 at 00:35
My apologies. My previous code stopped working and I am not sure why. However, I did find another solution with less code:
<div><!--fan content open tag-->
<fb:visible-to-connection>
- fan content here -
</div><!--fan content close tag-->
</fb:visible-to-connection>
I would say it's more of a hack than a standard practice. However, it works and at least it is Facebook and not your site that is considered "non-standard". :p
#16 by timware - September 2nd, 2010 at 09:33
What is your logic here? You open a DIV, then open an FBML tag, then close the DIV before closing the FBML tag. If this works on some browser, I think it's a fluke.
I appreciate that your trying to really minimize the code for the fans only content method, but my approach is probably as minimal as you'll get while still getting it to display properly over all browsers and platforms.
Also, there's no <fb:else> tags, so I guess you'd just have some content for fans and no content for non-fans?
#17 by Matthew Martindale - September 2nd, 2010 at 13:40
I think the bigger problem is Facebook not making a simple function easy to work with. No matter how you get it to work for you, it's not exactly ideal.
Your approach is definitely working, which is more than I can say after discovering this morning that my approach had stopped working (some of my issues might be due to caching, however). The logic behind the second solution I provided was someone else's, and I can't find the blog URL (sorry). At the time, it worked in all browsers, and it seemed to work for many others.
From what I have discovered, even is inconsistent.
#18 by selina - September 2nd, 2010 at 04:54
how do i hide the 'non-fans' part, after someone likes my page.
#19 by timware - September 2nd, 2010 at 09:35
Selina, You should get in the habit of reading tutorials closely before posting questions. As it says in the red NOTE near the beginning of this article, if you're logged into Facebook as a page admin while viewing the tab, you're going to see both fans and non-fans content.
#20 by Alex Holigores - September 4th, 2010 at 16:51
Thanks for the help with this, it's working great! Does anyone have any idea how to add comments to the "visible-to-connection" page only, and not fb:else?
Thanks!