Limit NewsFeed to Display Latest 5 Posts in SharePoint 2013

Sharing is Caring

I was having an issue to retrieve latest posts from newsfeed,lets say take 5 of them.Tried everything,but newsfeed webpart didnt support filtering according to my need.

So i tried a “css-trick” code i found over the internet and improved it to my needs:

function get5posts() {
var limit = 5;
$("#ms-feedthreadsdiv .ms-microfeed-thread").each(function (i) {
if (i >= limit) {

The code above shows only 5 posts on page load.But what happens if you add more in newsfeed? The 5 item limit exceeds and you need to call a function to restrict it to 5 item:

Call get5posts() in page load event:

$(document).ready(function (e) {

Afterwards call it again if user clicks on post reply button:

$("#ms-postbutton").on("click", function () {

This will limit NewsFeed to 5 posts only.

Nice Trick!