SharePoint 2013 add like functionality to publishing page with javascript

12/05/2013

It has been a while since I have posted a SharePoint specific blog post, it doesn’t mean that I haven’t been working with SharePoint, just that I have been stuck on SP2010 projects with little interesting to talk about. But now I’m also starting to work with SP2013 and hopefully over the summer I will be able to look into the SP2013 certifications too, so expect more SharePoint focused blog posts in the coming months.

In SharePoint 2013 the rating functionality that can be enabled on all libraries, have been extended with a simple like/unlike functionality in addition to the 5 star rating from SP2010. Obviously this is something the customers love, as it reminds them of their well-known facebook like functionality. Unfortunately Microsoft for some reason decided to only enable the functionality directly from the page library list view, where most end users will never end up when working with publishing sites.

Therefore I create the following piece of javascript that can be inserted on a page layout, so the end users can like/unlike the page when they open it. Of course it can be wrapped in a control, or even a field control if you want, but since there is nothing newsworthy in that, I will just present you with the javascript. Also note that this javascript could be nicer, but I’m more interested in presenting a solution, than the perfect solution, as most people probably have to tweak it to their needs anyway.

To use the script the following requirements must be met

Include the following javascript either directly in the page or preferably from your javascript file.

All that is left for you to do is to insert the following html on your page, where you want the number of likes to appear.

When you click on the number you like the page if you haven’t done so before, or unlike the page. Feel free to add your own text and images to the html inserted by the javascript to make it more appealing.

I uploaded a full example on how to add the like functionality to the ArtileLeft.aspx page layout, it can be done with SharePoint designer if you are after a no code solution.