How to activate Facebook Comments in Odoo
5 March, 2021 by
How to activate Facebook Comments in Odoo
Administrator

The Facebook Comments plugin lets people comment on content on your site using their Facebook account. People can choose to share their comment activity with their friends (and friends of their friends) on Facebook as well.  Let me show you how to add this nice feature to your Odoo based blog in some easy steps.

You need a Facebook application ID. If you don’t know how to get one, then read this.

In this tutorial I will be using Odoo 9.0 Community Edition.

Step 1:

Activate ‘Developer Mode’, click in the current user menu and select ‘About’. In the newly opened dialog you will find the option to activate it.

Step 2:

Go to Settings, in the left find ‘Technical Settings’ section, expand ‘User Interface’ and select ‘Views’

Step 3:

Search ‘Allow comment in Blog post’ and open it in ‘Edit’ mode.

Step 4:

Modify the content to this:

<?xml version="1.0"?>
<data name="Allow blog post comment" inherit_id="website_blog.blog_post_complete" active="False" customize_show="True">
  <xpath expr="//div[@id='blog_content']" position="after">
    <section id="comments" class="read_width">
      <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&amp;version=v2.6&amp;appId=YOUR_FACEBOOK_APP_ID";
        fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));
      </script>
      <div class="fb-comments" t-attf-data-href="https://YOUR_DOMAIN/blog/#{slug(blog_post.blog_id)}/post/#{slug(blog_post)}" data-numposts="5"></div>
      <hr/>
      <t t-call="website_mail.message_thread">
        <t t-set="object" t-value="blog_post"/>
        <t t-set="chatter_mode" t-value="'json'"/>
      </t>
    </section>
  </xpath>
</data>

Please pay attention, in the code in blue, you will need to replace YOUR_DOMAIN and YOU_FACEBOOK_APP_ID with your own values.

Step 5 (Final step):

Now everything you need is to activate ‘Allow comments in blog post’ in your website and that’s it.

I hope you find this little hack useful. Let me know what you think.