0

I'm trying to make a FB share on my Drupal website. I have a page with lots of different projects. When the user clicks on a project, the page extends (no reload) and the detailed images of that project become visible. I need to make it possible that the user can share that detailed image.

I added the meta property for og:image in my html code. When the user clicks on a project, the content of this property is changed to the right image. This works, the meta property changes the right way, I use jQuery for this. But FB is still sharing the original image, not the adjusted image.

Has anybody experience with this? Thanks

Simon H
  • 1
  • 1

1 Answers1

1

You shouldn´t just change the metatags with JavaScript, you have to do it server side. The Facebook crawler ignores JavaScript, for example.

The same question has been answered in several other threads already, this is what i found with a quick Google search:

If you need dynamic tags, use the feed dialog instead: https://developers.facebook.com/docs/sharing/reference/feed-dialog/v2.4

Community
  • 1
  • 1
andyrandy
  • 72,880
  • 8
  • 113
  • 130
  • Also, see https://developers.facebook.com/docs/sharing/webmasters/crawler and also https://prerender.io/ for example. – Tobi Jul 09 '15 at 08:12
  • Thank you for your reply. Yes indeed, I understand that FB crawler ignores JavaScript but I thought that this wouldn't be a problem since I first change the property. The change is done and only after that there is the possibility for sharing. I must say that I don't have experience with FB crawler and how it works... – Simon H Jul 09 '15 at 08:14
  • 1
    It's always a server-sided call, so it just ignores whatever you set in jQuery (or any other JS framework). As @luschn outlined, there are numerous of similar question. Please refer to those. – Tobi Jul 09 '15 at 08:16
  • I'm very sorry for the double question. But now I'm really stuck, I need to modify the metaproperty on the serverside when the user clicks on "share on FB". So I want the call PHP from jQuery...probably not right. As you know/see now, I'm a beginning developer...What would be the right way to do this or search this on the internet? – Simon H Jul 09 '15 at 09:03
  • use the feed dialog then. i´ve added a link in my answer. – andyrandy Jul 09 '15 at 09:22