O'Reilly logo

Facebook Cookbook by Jay Goldman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Displaying/Hiding Content to/from Specific Users

Problem

How do I display content only to a specific user?

Solution

Use the fb:if-is-user tag. The simplest form is:

<fb:if-is-user uid="12345">You're it!</fb:if-is-user>

Discussion

As with all fb tags that begin with if, you can use the fb:else tag inside the fb:if-is-user to provide alternate content if the user isn’t the droid you’re looking for:

<fb:if-is-user uid="12345">
    You're it!
    <fb:else>
        You aren't it.
    </fb:else>
</fb:if-is-user>

You might sometimes want to check for a bunch of different users you want to exclude from seeing some content. The tag supports comma-separated uids, and you can use the fb:else tag to actually do the inverse of the example just shown:

<fb:if-is-user uid="12345,54321,11111,22222">
    <!-- No content here -->
    <fb:else>
        Everyone else sees this bit here.
    </fb:else>
</fb:if-is-user>

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required