Quickest way to add Facebook Like Button on your SharePoint page

By Namwar Rizvi - Last updated: Monday, April 4, 2011 - Save & Share - 8 Comments

Facebook is everywhere. No one can deny the importance of Facebook’s social media┬ácapabilities.

If you want to add the Facebook Like button on your SharePoint pages then just paste the following code in a Content Editor Web Part and you will instantly get the Like button for that page. You do not need to hardcode the URL of your page as the given code automatically find it for you.

Just copy paste it and enjoy!

<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>
<SCRIPT LANGUAGE="JavaScript">

      <!--
      {
       var url = location.href;
       var url_parts = url.split('?');
       var main_url = url_parts[0];
       var facebookLike="<fb:like href='" + main_url + "' show_faces='true' width='450' font=''></fb:like>"

       document.write(facebookLike);
      }
      // -->
</SCRIPT>

Share
Posted in How To, JavaScript, Social Media, Solutions, Tips, WebPart • Tags: , , , , Top Of Page

8 Responses to “Quickest way to add Facebook Like Button on your SharePoint page”

Comment from julien
Time April 5, 2011 at 12:01 pm

hello, I cannot get the tips working on my SP2010…
I paste the code on a content editor, but when I test the link it says:
The url is not valid…
do you know this error?

Comment from namwar
Time April 10, 2011 at 5:14 pm

Hi julien,
To find out what is the issue, add the following line of code at line no. 10 above:

alert(main_url);

It will display the url and will give you the idea why you are getting the error.

Comment from bd
Time June 15, 2011 at 6:45 pm

nothing showed up for me, maybe it is being blocked by our firewall.

Comment from bd
Time June 15, 2011 at 6:51 pm

yes, when I look at the source it tells me it has been blocked. I’ll have to find another way.

Comment from Vilcek
Time June 17, 2011 at 1:34 pm

Hi,

I put it in Contect Editor in web part, but it just show the code on the page. it does not display the like button….:(

Comment from Debprotim
Time August 26, 2011 at 12:06 pm

Hi Vilcek,

You need to paste the code in ‘Source Editor’ part of content editor webpart.

Comment from Steve
Time December 2, 2011 at 3:55 pm

This is so cool but I have a problem. I keep getting warnings from IE and I have to click “Allow all Content to show” and then the page refreshes and when it comes back I have two like buttons. Can someone tell me what I’m doing wrong?
Thanks.

Comment from Pravin
Time September 4, 2013 at 4:47 am

Hi Debprotim,
I don’t get it what you mean by the source editer. Could explain more clearer? Or give an example of codes? Thank you very much:)

Write a comment