user2554971
user2554971

Reputation: 11

How do I dynamically generate og meta data for Facebook sharing based on content on that page?

I'm trying to figure out a simple way of using PHP to dynamically generate OG meta information for Facebook sharing such as og:title, og:description and other tags based on content that is already on a page.

Here's the URL for reference: http://jonathanmitchell.ca/OPEC/new3.php

The og:title I want to draw from is the "This is the title" which has an ID of news-story-title-on-template.

Any help at all would be really appreciated ... thanks!

Upvotes: 1

Views: 2124

Answers (1)

Sahil Mittal
Sahil Mittal

Reputation: 20753

You can generate the dynamic og tags.

For eg you want to assign og tags the values according to an ID-

Your object url: http://myobject.com?id=ID

<?php
$id = $_GET['id'];
// manipulate title and image with this id, say $title / $image
?>
<meta property="og:url" content="http://myobject.com?id=<?php echo $id; ?>" />
<meta property="og:app_id" content="APP_ID" />
<meta property="og:title" content="<?php echo $title; ?>" />
<meta property="og:image" content="<?php echo $image; ?>"/>

If you are passing any parameter to your object url, make sure you add the same to the og-tag: og:url (as I've shown in above example)

Upvotes: 1

Related Questions