Display Content to Group Members

Problem

How do I display content only to members of a specific group?

Solution

Use the fb:if-is-group-member tag and specify the group ID. The simplest form is:

<fb:if-is-group-member gid="12345">Private content goes here</fb:if-is-group-member>

Discussion

You can use this tag in combination with the fb:else tag to display alternate content to people who aren’t in the group. The tag will default to checking for the loggedinuser, but you can also specify a different uid if you want to check a different member:

<fb:if-is-group-member gid="12345" uid="12345">
    Private content goes here
    <fb:else>
        Sorry! You're not in <fb:grouplink gid="12345"/>.
    </fb:else>
</fb:if-is-group-member>

Since groups support different roles (member, admin, officer), you can also use the fb:if-is-group-member to check for a user’s access level:

<fb:if-is-group-member gid="12345" uid="12345" role="admin">
    Private content for admins goes here
    <fb:else>
        Sorry! You're not an admin of <fb:grouplink gid="12345"/>.
    </fb:else>
</fb:if-is-group-member>

Get Facebook Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.