Frank Furter
Frank Furter

Reputation: 508

Modifying Facebook share content with JavaScript

I've been successfully using the Sharrre plugin to add a Facebook share button to a page but I now need to change the title and description of the shared link.

I believe this was possible in the past before Facebook updated sharer.php, with the new version no longer accepting parameters for title, etc. I can change the og:title attribute content via JavaScript but when Facebook requests the page these changes are (obviously) not present.

How are sites like Buzzfeed accomplishing this with their quizzes, where the outcome is shared?

Upvotes: 0

Views: 64

Answers (1)

Artek Wisniewski
Artek Wisniewski

Reputation: 797

You need to detect the Facebook scraper server side, they use unique User Agent string.

I use this one

preg_match('/facebookexternalhit/i', $_SERVER['HTTP_USER_AGENT'])

Based on this, change og:title and og:description, when FB scrapes your website it will see changed params.

Upvotes: 1

Related Questions