Sharethis facebook

I’m implementing this functionality on a different part of my site so thought I would go ahead and put the solution here. It’s actually pretty simple. :slight_smile:

In php tags at the top of your page…

$tripbit_id = $_GET['tripbit_id'];

$json = file_get_contents('path/to/your/serverconnect?tripbit_id=' . $tripbit_id);

$data = json_decode($json, true);

$params['title'] = $data["query"]["title"];
$params['image'] =  $data["query"]["img"];
$params['description'] = $data["query"]["description"];
$params['url'] = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

And then in your head tags…

        <meta property="og:url" content="<?php echo $params['url']; ?>" />

        <meta property="og:type" content="website" />

        <meta property="og:locale" content="en_US" />

        <meta property="og:title" content="<?php echo $params['title']; ?>" />

        <meta property="og:image" content="<?php echo $params['image']; ?>" />

        <meta property="og:description" content="<?php echo $params['description']; ?>" />

HTH…

5 Likes