Search code examples
htmlfacebookfacebook-social-pluginsfacebook-sharer

Share and add a custom message?


I've integrated a Facebook share button into my site. The client now wishes to add a prepopulated message when a user presses the share button, so this can be written to the users timeline. (If they agree).

I've checked out the share button on facebook:

https://developers.facebook.com/docs/plugins/share-button/

But I cant find anywhere how to add a custom message to the share button?


Solution

  • You'll need to add facebooks OG tags to the head of your page, Facebook will read these and add the content. You can add a custom title, image and description.

    <meta property="og:title" content="title" />
    <meta property="og:description" content="description" />
    <meta property="og:image" content="http://www.website.com/thumbnail" />
    

    If you need to add a custom title, image or description per page then you'll need to use a php constant to define these on a per-page basis.

    With something like:

    <?php 
    $title = 'Title Here';
    $desc = 'Description goes here...';
    ?>
    

    Then the meta tags would look like this.

    <meta property="og:title" content="<?php echo $title ?>" />
    <meta property="og:description" content="<?php echo $desc ?>" />
    <meta property="og:image" content="http://www.website.com/thumbnail" />
    

    Check out the docs here: