0
votes

Is there a way to define the facebook Open Graph meta tags (OG) with a link?

For example I have a single page website with several anchors.

At each anchor I have a sub heading and an image

The url would be : www.mywebsite.com/#page2

When using the facebook share function I'd like to define that URL with a defined sub heading as the title, and the the image in the sub heading as the image that is shared on facebook.

Is this possible? Is it possible with PHP or JS?

1
Do you have a specific code example that you're struggling with? - David Wyly
It's more of a theoratical qustion to see if it's possible. I'm in the process of building a single page site. and one of the concerns that came up with regarding creating a sharable link. I underst facebook scrpaes for property="og:image" property="og:url" property="og:title" in the header tag. However this is a single page site, but i would like to be able to share #(or anchor tags) that populate the OG meta tag properites. - Sao Tith
What i'm asking is "is it possible to create a dynmaic open graph meta tags?" using php or javascript? if so how? - Sao Tith
Of course it is possible using PHP (or any other server-side technology), but that needs an individual URL for each individual item you want to share (and a different hash part only does not make them different URLs). It is not possible via client-side JavaScript, because the Facebook scraper does not interpret that. - CBroe

1 Answers

0
votes

I would advise you to implement the Google Ajax URL specification. It specifies how to treat single-page website when indexing for the Google search engine, but Facebook also uses it when indexing Open Graph information.

You can read more on the specification here: https://developers.google.com/webmasters/ajax-crawling/docs/specification

I basically works by mapping http://www.example.com/#!section to http://www.example.com/_escaped_fragment_=section. This way you, at the server side, can respond to the _escaped_fragment_ variable, when given.

When using this method, please be aware that the Facebook crawler will still follow meta og:url and link rel=canonical tags as the final url. So, if you return with the _escaped_fragment_ method, you can remove these tags (or set them to the current url).