Embed Facebook Messenger widget in your website

Facebook introduced new Messenger widget, It allows website/blog owners to provide their users with an easy way to message/contact or ask any query through facebook page or profile. In this article, we will show you how to embed/integrate Messenger widget in your site. There are various techniques, I will explain each technique step by step.

facebook-messenger

Messenger Link

<a href="https://m.me/coderexample">
    Message us on Facebook
 </a>
 

This is the most simple method, you need to just add Messenger link in a hyperlink, make sure your have used your profile/page username with Messenger link. Clicking on the link will take you Messenger interface to message.

Messenger Box

You can also add messenger box like “facebook like box”. To generate embed code you need go Facebook Page Plugin Documentation

Then you need to add facebook javascript SDK https://developers.facebook.com/docs/reference/javascript/ in your site. you can include this before <body> tag started.

<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.6&appId=496223437090509";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

Now you can paste below code where you want to show Messenger Box on your site.

<div class="fb-page" data-href="https://www.facebook.com/coderexample" data-tabs="timeline,messages" data-small-header="false" data-adapt-container-width="true" data-hide-cover="false" data-show-facepile="true">
    <blockquote cite="https://www.facebook.com/coderexample" class="fb-xfbml-parse-ignore">
        <a href="https://www.facebook.com/coderexample">CoderExample</a>
    </blockquote>
</div>

data-tabs defined various tabs like timeline, messages or events. you can keep only one tab or use a comma-separated list to add multiple tabs, i.e. timeline, events.

Iframe Technique

If you don’t want to add facebook SDK on your site you can refer iframe technique but It’s not a good practice for a site performance.

just copy paste below iframe code where you want to show Messenger Box on your site.

<iframe src="https://www.facebook.com/plugins/page.php?href=https:%2F%2Fwww.facebook.com%2Fcoderexample&tabs=timeline%2Cmessages&width=340&height=500&small_header=false&adapt_container_width=true&hide_cover=false&show_facepile=true&appId=496223437090509" width="340" height="500" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowTransparency="true"></iframe>

Note:

To enable messaging on your Facebook page go to your Page Settings. In the row Messages check Allow people to contact my Page privately by showing the Message button (Direct Link: https://www.facebook.com/{your-page-name}/settings/?tab=settings&section=messages&view).

DownloadDemo


  • jhonatansevilla

    how can do this on my site?

  • Rajeev Kumar

    Can i use this in wordpress site at https://tutorialwing.com ?

  • Maurice Malherbe

    Thanks a lot for your article, I really appreciate it. We are also using another great messenger plugin which is called cvita on http://www.meininfoprodukt com. For http://www.smartgig.ch we are using the chatfuel autobot which already created the messenger id for the site and it’s working great. 🙂