Fixed Open Graph Implementation

digitalpoint

Well-known member
A couple issues here...

The main forum page is tagged in Open Graph as an "article", rather than a "website". This makes it so when someone likes your main page, their Facebook feed shows they liked an article. This came to my attention when I liked my site and my mom calls me up to tell me she tried to read the article I liked, but it just took me to my website. :)

https://developers.facebook.com/docs/technical-guides/opengraph/built-in-objects/#external_profile

Member profiles are also tagged as "article" instead of "profile". In addition, there's also some extra profile tags that can be used in Open Graph... This is how I changed it in my member_view template as an example:

Code:
<xen:container var="$head.openGraph"><xen:include template="open_graph_meta">
<xen:set var="$url">{xen:link 'canonical:members', $user}</xen:set>
<xen:set var="$title">{$user.username}</xen:set>
<xen:set var="$type">profile</xen:set>
<xen:set var="$extra"><meta property="profile:username" content="{$user.username}" />
<xen:if is="{$user.gender}"><meta property="profile:gender" content="{$user.gender}" /></xen:if></xen:set>
<xen:set var="$avatar">{xen:helper avatar, $user, 'm', '', 'true'}</xen:set>
</xen:include></xen:container>
/kick TinyMCE and tabs

You could do other things like birthdate and stuff, but I didn't care enough to add them. :)

The open_graph_meta template was changed to use $type and $extra to feed in extra secondary fields (like profiles).

XenForo only puts Open Graph data on pages that you can embed the Facebook Like button, but it probably wouldn't be a bad idea to use Open Graph on forum display pages as well... it's a fairly common page to like (even without a FB button).
 
I didn't want to create a new thread for this (as all new Xenforo installations won't experience the issue), but it's worth noting that some people may get a "Cannot change og_type" error through Facebook's debugger with this fix, due to the incorrect og:type being used in the first place.

https://developers.facebook.com/tools/debug/og/object?q=http://xenforo.com/community/
Cannot change og_type:
The object at 'http://xenforo.com/community/' previously had type 'article' and cannot be changed to an object of type 'website' to avoid data corruption of existing actions.
 
I've been reading all the threads on Facebook OpenGraph and it looks like xF integrates it all here. I'm still having issues with Facebook picking up user avatar instead of the images in posts when someone clicks on 'Like' or 'Share' button on.

Is there any easy way to fix this up?
 
Top Bottom