A collection of custom CSS snippets for Smash Balloon feeds, and where to paste them so they survive plugin updates.
Would you like to change how your Facebook feed looks or behaves with a few lines of code?
Facebook Feed gives you many settings, but some changes need a small snippet of CSS or JavaScript. This guide collects ready-made snippets you can copy, from simple borders and shadows to pinned posts, custom post titles, and captions on photo grids.
Each recipe says what it does, where it works, and which part of the snippet you can change.
Before you get started, make sure Facebook Feed is installed and activated on your site. The feed you want to change must already be on a page.
- Where to Add Your Code
- CSS Snippets
- JavaScript Snippets
- Crop Images to a Fixed Size
- Pin a Post to the Top
- Add an Invite Link to Events
- Add Captions to a Photos Grid
- Match Shared Link Posts to Photo Posts
- Insert Your Own Content Every Few Posts
- Create a Custom Post Title
- Remove a Hashtag From the Post Text
- Link Photos to a URL in the Post Text
- Reverse the Order of Comments
- Add Dates to Photo, Video, and Album Feeds
- Change the Author Avatar Size
- Add Event Details to the Lightbox
- Link the Header to Your Facebook Page
- Remove Cover Photo Update Posts
- Add a Pinterest Pin It Button
- More Layouts
- Frequently Asked Questions
Where to Add Your Code
CSS and JavaScript go in different places. CSS goes in the Additional CSS area of WordPress. JavaScript goes in our code snippets plugin, WPCode. The boxes for custom CSS and custom JavaScript inside the plugin settings are deprecated. Instead, use the places below.
To add CSS, go to Appearance » Customize » Additional CSS in your WordPress dashboard and paste the snippet. If your theme is a block theme, the menu looks different. Our custom CSS guide covers adding custom CSS and block themes.

To add JavaScript, paste the code into the Footer section of WPCode, so it loads after your feed. Our custom JavaScript guide shows each step. Every JavaScript recipe below is already inside the template the plugin uses. Paste it as it is. After you save a snippet, reload the page that shows your feed to see the change. If you use a caching plugin, clear its cache first. The empty template looks like this.
<!-- Custom Facebook Feed JS -->
<script type="text/javascript">
function cff_custom_js($){
var $ = jQuery;
//Add your Custom JavaScript here
}
cff_custom_js(jQuery);
</script>

When a visitor clicks the Load More button, the plugin runs cff_custom_js again after the new posts load. Recipes that add or move something on a post mark the posts they have already changed, so the change is never made twice.
To use more than one JavaScript recipe, put them all in one snippet with a single copy of the template. From each recipe, copy the lines between var $ = jQuery; and the closing } of the function. Then paste them one after another inside your template. Every recipe uses the same function name, cff_custom_js. In separate snippets, the last one replaces the others, so only that recipe runs again after Load More.
Several recipes change a post that you pick by its ID or by its author class. To find either one, right-click the post on your page and click Inspect. Then look at the opening tag of the post. Its id starts with cff_ and its class list includes an author- class.
CSS Snippets
These recipes only need CSS. Paste them into Additional CSS as described above.
Show the Comments Box by Default
By default, the comments box under each post stays closed until a visitor clicks to open it, so each post takes less room. The builder can show it from the start with no code. The Expand Comments box by default switch is under Customize » Posts » Edit Individual Elements » Likes, Shares and Comments.
This snippet does it with CSS instead, for every feed on your site at once. It shows the box, with as many comments as your feed is set to show, as soon as the page loads. It works on feeds that show comments.
#cff .cff-comments-box {
display: block;
}
Add a Border to Your Feed
This snippet draws a border around the whole feed. Change the width, the style, and the color in the second line.
#cff {
border: 1px solid #000;
}
Make Link Thumbnails Larger
In some feeds, the picture from a shared link shows as a small thumbnail. The next snippet makes it as large as the picture in the half-width layout.
#cff .cff-link {
width: 50%;
max-width: none;
}
#cff .cff-link img {
max-width: none;
width: 100%;
}
#cff .cff-text-link {
width: 47%;
}
To make the thumbnail as large as the picture in the full-width layout, use this snippet instead.
#cff .cff-link {
width: 100%;
max-width: none;
}
#cff .cff-link img {
max-width: none;
width: 100%;
}
#cff .cff-text-link {
width: 100%;
}
Remove the Fixed Height on Mobile
If you set a fixed height for the feed, the feed gets a scroll bar. This snippet removes the fixed height on small screens. Phones then show the whole feed with no scroll bar.
@media all and (max-width: 480px) {
.cff-wrapper-ctn.cff-wrapper-fixed-height {
height: auto !important;
}
}
Add a Shadow to Posts
If your posts use the boxed style, the Box Shadow checkbox under Customize » Posts » Post Style adds a shadow with no code. For more control, this snippet adds a shadow around each post.
#cff .cff-item {
box-shadow: 0 0 5px 5px rgba(0,0,0,0.5);
}
To make the shadow grow when a visitor points at a post, add this snippet as well.
#cff .cff-item:hover {
box-shadow: 0 0 5px 10px rgba(0,0,0,0.5);
}
To change the size, the spread, or the color of the shadow, see the box-shadow reference on MDN.
Set Semi-Transparent Backgrounds
To make a background see-through with CSS, use a color with an alpha value.
In rgba(54, 25, 25, 0.5), the last number is the transparency. It runs from zero, which is fully see-through, to one, which is fully solid.
First, clear any background color you set for that part of the feed in the builder. Otherwise, the builder color can override your CSS.
Then add one or more of the snippets below. The first one sets the background of the whole feed.
.cff-wrapper {
background: rgba(54, 25, 25, 0.5);
}
This snippet sets the background of the text in each post.
.cff-post-text {
background: rgba(54, 25, 25, 0.5);
}
This snippet sets the background of the date.
.cff-date {
background: rgba(54, 25, 25, 0.5);
}
This snippet sets the background of the View on Facebook link.
.cff-viewpost-facebook {
background: rgba(54, 25, 25, 0.5);
}
You can paste any color you like in place of rgba(54, 25, 25, 0.5). A color picker tool online will give you the full value.
Style Posts by Author
If several people post to your Page, or you show posts from more than one Page, you can style each author differently. Every post carries a class built from the author name, so one line of CSS can change the background of all posts by that author.
.author-my-name {
background: #abc123;
}
.author-my-awesome-page {
background: #ff0000;
}
.author-another-page {
background: #321cba;
}
The three class names above are examples. Replace them with your own.
To build the class, write the author name in lowercase and turn every run of spaces, symbols, or accented letters into one hyphen. A hyphen that is already in the name stays. For example, “My Awesome Page” becomes .author-my-awesome-page, and “My Page’s News” becomes .author-my-page-s-news. Keep the dot at the start.
The surest way to get the class right is to use Inspect on one of the posts and copy the author- class from its tag.
JavaScript Snippets
These recipes need JavaScript, and some also need a little CSS. Add the JavaScript with WPCode, and add any CSS with Additional CSS, as described at the start of this guide.
Crop Images to a Fixed Size
Photos in a feed come in different shapes. These two recipes crop every photo and video to the same size and keep the middle of the picture in view. The first sets a fixed height and lets the width follow the feed. The second sets a fixed height and width. If you are not sure which to pick, start with the fixed height, because it is shorter and works in every layout. Next, choose the fixed height and width when your posts show the picture beside the text in the Half width or Thumbnail layout.
For the fixed height, first add this CSS. Change the 200px value to the height you want.
#cff .cff-photo,
#cff .cff-html5-video,
#cff .cff-event-thumb {
height: 200px;
width: 100%;
}
.cff-multiple {
overflow: hidden;
}
Then add this JavaScript. It hides each picture and uses it as a centered background instead.
<!-- Custom Facebook Feed JS -->
<script type="text/javascript">
function cff_custom_js($){
var $ = jQuery;
$('.cff-photo, .cff-html5-video, .cff-event-thumb').not('.cff-crop-done').each(function(){
var $box = $(this),
src = $box.find('img').attr('src');
if (!src) return;
$box.addClass('cff-crop-done');
$box.find('img, video').hide();
$box.css({
'background': 'url(' + src + ') no-repeat center center',
'background-size': 'cover'
});
});
}
cff_custom_js(jQuery);
</script>
For a fixed height and width, add this CSS instead. The 535px value is the smallest screen width where the crop applies. The 50% and 300px values are the width and height of each picture. The 49% value is the width of the post text next to it.
@media all and (min-width: 535px) {
#cff .cff-photo,
#cff.cff-half-layout .cff-photo,
#cff.cff-thumb-layout .cff-photo,
#cff .cff-html5-video,
#cff.cff-half-layout .cff-html5-video,
#cff.cff-thumb-layout .cff-html5-video {
position: relative !important;
width: 50% !important;
height: 300px !important;
overflow: hidden !important;
}
#cff .cff-photo img,
#cff.cff-half-layout .cff-photo img,
#cff.cff-thumb-layout .cff-photo img,
#cff .cff-html5-video video,
#cff.cff-half-layout .cff-html5-video video,
#cff.cff-thumb-layout .cff-html5-video video {
position: absolute !important;
left: 50% !important;
top: 50% !important;
height: 100%;
width: auto;
max-width: none;
transform: translate(-50%, -50%);
}
#cff .cff-photo img.portrait,
#cff.cff-half-layout .cff-photo img.portrait,
#cff.cff-thumb-layout .cff-photo img.portrait,
#cff .cff-html5-video video.portrait,
#cff.cff-half-layout .cff-html5-video video.portrait,
#cff.cff-thumb-layout .cff-html5-video video.portrait {
height: auto;
width: 100%;
}
#cff.cff-half-layout .cff-text-wrapper {
width: 49%;
}
}
Then add this JavaScript. It marks the pictures that are taller than they are wide. The CSS can then fit them to the width instead.
<!-- Custom Facebook Feed JS -->
<script type="text/javascript">
function cff_custom_js($){
var $ = jQuery;
$('#cff .cff-photo img, #cff .cff-html5-video video').not('.cff-portrait-done').each(function(){
var $media = $(this),
width = this.naturalWidth || this.videoWidth || 0,
height = this.naturalHeight || this.videoHeight || 0;
if (width < 1 || height < 1) return;
$media.addClass('cff-portrait-done');
if (width < height) $media.addClass('portrait');
});
}
cff_custom_js(jQuery);
</script>
A picture that has not finished loading when the script runs is skipped. If a picture is not cropped, reload the page.
Pin a Post to the Top
You can pin a post by moving it to the top of your feed yourself.
First, find the ID of the post, as described at the start of this guide. It starts with cff_.
Then replace cff_your_post_id in this snippet with that ID. The post is moved only if it is in the feed. Nothing happens when the post is not among the posts that have loaded.
<!-- Custom Facebook Feed JS -->
<script type="text/javascript">
function cff_custom_js($){
var $ = jQuery;
var $pinned = $('#cff_your_post_id').not('.cff-pinned-done');
if ($pinned.length) {
$pinned.addClass('cff-pinned cff-pinned-done');
$('#cff .cff-item').first().before($pinned);
}
}
cff_custom_js(jQuery);
</script>
To style the pinned post, add this CSS.
.cff-pinned {
padding: 10px !important;
border: 1px solid rgba(0,0,0,0.3);
box-shadow: 0 0 10px 0 rgba(0,0,0,0.15);
}
Add an Invite Link to Events
You can add an Invite link to the bottom of each event. It takes visitors to the event on Facebook, where they can invite other people.
It works on events feeds. It needs the View on Facebook link to be on, because it copies that link.
<!-- Custom Facebook Feed JS -->
<script type="text/javascript">
function cff_custom_js($){
var $ = jQuery;
$('#cff .cff-event').not('.cff-invite-done').each(function(){
var $event = $(this),
href = $event.find('.cff-viewpost').first().attr('href');
if (!href) return;
$event.addClass('cff-invite-done');
$event.find('.cff-post-links').prepend('<a class="cff-viewpost" href="' + href + '" target="_blank">Invite</a><span class="cff-dot">·</span>');
});
}
cff_custom_js(jQuery);
</script>
Add Captions to a Photos Grid
A Photos grid shows pictures with no text. This snippet adds the caption of each photo below it. It reads the caption from the picture, so it works whether or not the lightbox is turned on.
Change 100 to show more or fewer characters.
<!-- Custom Facebook Feed JS -->
<script type="text/javascript">
function cff_custom_js($){
var $ = jQuery;
function cffDecode(text){
var box = document.createElement('textarea');
box.innerHTML = text;
return box.value;
}
$('.cff-album-item').not('.cff-caption-done').each(function(){
var $item = $(this),
caption = $.trim(cffDecode($item.find('.cff-album-cover img').first().attr('alt') || ''));
if (caption === '') return;
$item.addClass('cff-caption-done');
$item.append($('<p class="cff-photo-caption"></p>').text(caption.substring(0, 100)));
});
}
cff_custom_js(jQuery);
</script>
Then add this CSS to give the caption some room.
.cff-photo-caption {
padding: 5px;
height: 100px;
overflow: hidden;
}
To show the caption only when a visitor points at a photo, use the same JavaScript. Change 100 to 500. Then use this CSS in place of the one above.
#cff .cff-album-item {
position: relative;
}
#cff .cff-album-item .cff-photo-caption {
display: none;
position: absolute;
left: 0;
right: 0;
bottom: 0;
margin: 0;
padding: 5px;
max-height: 100%;
overflow: hidden;
color: #fff;
background: rgba(0,0,0,0.6);
}
#cff .cff-album-item:hover .cff-photo-caption {
display: block;
}
Match Shared Link Posts to Photo Posts
Posts that share a link look different from photo and video posts. These recipes move the link picture to the left of the text, so the two kinds of post line up.
The layout comes from the setting at Customize » Posts » Layout. First, choose Thumbnail or Half width there. Then follow the matching recipe.
For the thumbnail layout, add this CSS.
#cff .cff-shared-link {
width: 20%;
margin: 0;
background: none;
border: none;
}
#cff.cff-thumb-layout .cff-full-size .cff-link {
max-width: 100%;
}
#cff.cff-thumb-layout .cff-link-item .cff-text-wrapper {
width: 77%;
}
#cff .cff-shared-link .cff-text-link {
display: none;
}
For the half-width layout, add this CSS instead.
#cff .cff-shared-link {
width: 50%;
margin: 0;
background: none;
border: none;
}
#cff.cff-half-layout .cff-full-size .cff-link {
max-width: 100%;
}
#cff.cff-half-layout .cff-link-item .cff-text-wrapper {
width: 47%;
}
#cff .cff-shared-link .cff-text-link {
display: none;
}
Both layouts then use the same JavaScript. It moves the link picture in front of the post text, and removes the picture when the post has no text next to it.
<!-- Custom Facebook Feed JS -->
<script type="text/javascript">
function cff_custom_js($){
var $ = jQuery;
$('#cff .cff-item').not('.cff-sharedlink-done').each(function(){
var $post = $(this),
$textWrapper = $post.find('.cff-text-wrapper'),
$sharedLink = $post.find('.cff-shared-link');
if ($sharedLink.length < 1) return;
$post.addClass('cff-sharedlink-done');
if ($textWrapper.length < 1) {
$sharedLink.remove();
return;
}
$textWrapper.before($sharedLink);
});
}
cff_custom_js(jQuery);
</script>
Insert Your Own Content Every Few Posts
You can place a block of your own content, such as a banner or a call to action, between the posts of your feed. Each of the three recipes below counts the posts in the feed and adds your content after every fifth post. Change numberOfPosts to change how often it appears.
This first snippet adds the same content after every fifth post. Replace the text in contentToAdd with your own text or HTML.
<!-- Custom Facebook Feed JS -->
<script type="text/javascript">
function cff_custom_js($){
var $ = jQuery;
var numberOfPosts = 5,
contentToAdd = 'Your content here',
count = 0;
$('#cff .cff-item').not('.cff-inserted-content').each(function(){
var $post = $(this);
count++;
if ($post.hasClass('cff-insert-done')) return;
$post.addClass('cff-insert-done');
if (count % numberOfPosts === 0) {
$post.after('<div class="cff-item cff-inserted-content">' + contentToAdd + '</div>');
}
});
}
cff_custom_js(jQuery);
</script>
To do this for only one feed, add a class to that feed first, as in the shortcode [custom-facebook-feed feed=1 class="feed1"]. The class can have any name, as long as the snippet uses the same one. Then use this snippet, which only looks at the feed with that class.
<!-- Custom Facebook Feed JS -->
<script type="text/javascript">
function cff_custom_js($){
var $ = jQuery;
var numberOfPosts = 5,
contentToAdd = 'Your content here',
count = 0;
$('#cff.feed1 .cff-item').not('.cff-inserted-content').each(function(){
var $post = $(this);
count++;
if ($post.hasClass('cff-insertone-done')) return;
$post.addClass('cff-insertone-done');
if (count % numberOfPosts === 0) {
$post.after('<div class="cff-item cff-inserted-content">' + contentToAdd + '</div>');
}
});
}
cff_custom_js(jQuery);
</script>
To show different content each time, put your blocks in a list. This snippet uses the first block after the fifth post, the second block after the tenth post, and so on. It stops when the list runs out.
<!-- Custom Facebook Feed JS -->
<script type="text/javascript">
function cff_custom_js($){
var $ = jQuery;
var numberOfPosts = 5,
contentToAdd = ['Content 1', 'Content 2', 'Content 3'],
count = 0;
$('#cff .cff-item').not('.cff-inserted-content').each(function(){
var $post = $(this),
index;
count++;
if ($post.hasClass('cff-insertlist-done')) return;
$post.addClass('cff-insertlist-done');
index = count / numberOfPosts - 1;
if (count % numberOfPosts === 0 && index < contentToAdd.length) {
$post.after('<div class="cff-item cff-inserted-content">' + contentToAdd[index] + '</div>');
}
});
}
cff_custom_js(jQuery);
</script>
Create a Custom Post Title
Posts have no title of their own, but you can make one from the post text. There are four ways to do it. Pick the one that matches how you write your posts. The first suits you if you want a title made for you and do not want to change your posts. The second and third suit posts that already start with a headline line. The fourth suits you if you want to decide the exact title text yourself.
The first uses the first 50 characters of the post as a heading. It adds three dots when the post is longer. Change 50 in both places to change the length.
<!-- Custom Facebook Feed JS -->
<script type="text/javascript">
function cff_custom_js($){
var $ = jQuery;
$('#cff .cff-item').not('.cff-title50-done').each(function(){
var $post = $(this),
postText = $post.find('.cff-text').text(),
ellipsis = postText.length < 50 ? '' : '...';
if (postText === '') return;
$post.addClass('cff-title50-done');
$post.prepend($('<h3 class="cff-post-title"></h3>').text(postText.substr(0, 50) + ellipsis));
});
}
cff_custom_js(jQuery);
</script>
To space the title, add this CSS.
.cff-post-title {
margin-bottom: 20px;
}
The second way styles the first line of each post, so it looks like a title. It needs only CSS, so it goes in Additional CSS. The first line is the line as it shows on screen, so on a phone it can stop partway through a sentence.
.cff-post-text::first-line {
font-weight: bold;
font-size: 22px;
}
The third way makes the first paragraph of the post bold and larger. This snippet splits the text at the first line break. If a post has no line break, the whole post text gets the title style.
<!-- Custom Facebook Feed JS -->
<script type="text/javascript">
function cff_custom_js($){
var $ = jQuery;
$('.cff-text').not('.cff-titleline-done').each(function(){
var $text = $(this),
parts = $text.html().split('<br>'),
firstLine = parts.shift();
$text.addClass('cff-titleline-done');
$text.html('<b style="font-size: 22px;">' + firstLine + '</b>' + (parts.length ? '<br>' + parts.join('<br>') : ''));
});
}
cff_custom_js(jQuery);
</script>
The fourth way lets you choose the title yourself. Write the title between two vertical bars at the start of your Facebook post, as in the example below.
| Title text |
Rest of the post text
Then add this snippet. It turns the text between the bars into a heading after the author, and removes it from the post text.
<!-- Custom Facebook Feed JS -->
<script type="text/javascript">
function cff_custom_js($){
var $ = jQuery;
$('#cff .cff-item').not('.cff-titlemark-done').each(function(){
var $post = $(this),
$text = $post.find('.cff-text').first(),
$author = $post.find('.cff-author').first();
if ($text.length < 1 || $author.length < 1) return;
var postHtml = $text.html(),
start = postHtml.indexOf('|') + 1,
end = postHtml.indexOf('|', start),
title = postHtml.substring(start, end);
$post.addClass('cff-titlemark-done');
if (start > 0 && end > start && title.length > 1) {
$author.after($('<h3 class="cff-post-title"></h3>').html(title));
$text.html(postHtml.replace('|' + title + '|', ''));
}
});
}
cff_custom_js(jQuery);
</script>
Remove a Hashtag From the Post Text
If you use a hashtag to filter your feed, such as #showonwebsite, you may not want it to show in the posts. This snippet removes any text you list.
Replace the examples with your own hashtags. Add more to the list as you need them. The match is exact, so write each hashtag with the same capital letters you use in your posts.
<!-- Custom Facebook Feed JS -->
<script type="text/javascript">
function cff_custom_js($){
var $ = jQuery;
var hashtags = ['#hashtag1', '#hashtag2'];
$('#cff .cff-item').each(function(){
var $text = $(this).find('.cff-text').first();
if ($text.length < 1) return;
var postHtml = $text.html();
$.each(hashtags, function(i, tag){
postHtml = postHtml.split(tag).join('');
});
$text.html(postHtml);
});
}
cff_custom_js(jQuery);
</script>
Link Photos to a URL in the Post Text
By default, clicking a photo opens it in the lightbox. These recipes send visitors to a web page of your choice instead. This is useful for a shoppable feed.
The lightbox opens before your link does, so turn it off first. To do this, go to Facebook Feed » All Feeds and edit your feed. Next, click Customize. Then click Lightbox and turn off the Enable switch.
To link the photo of a single post, use its ID, as described at the start of this guide. Replace cff_your_post_id with that ID and the web address with your own.
<!-- Custom Facebook Feed JS -->
<script type="text/javascript">
function cff_custom_js($){
var $ = jQuery;
function cffLinkPhoto($photo, url){
if ($photo.is('a')) {
$photo.attr('href', url);
} else {
$photo.css('cursor', 'pointer').off('click.cffPhotoLink').on('click.cffPhotoLink', function(){
window.location.href = url;
});
}
}
cffLinkPhoto($('#cff_your_post_id').find('.cff-photo'), 'https://example.com/your-page');
}
cff_custom_js(jQuery);
</script>
To link many posts at once, use this snippet. It finds the first link in the post text that does not point to Facebook, and sends the photo there.
<!-- Custom Facebook Feed JS -->
<script type="text/javascript">
function cff_custom_js($){
var $ = jQuery;
function cffLinkPhoto($photo, url){
if ($photo.is('a')) {
$photo.attr('href', url);
} else {
$photo.css('cursor', 'pointer').off('click.cffPhotoLink').on('click.cffPhotoLink', function(){
window.location.href = url;
});
}
}
$('#cff .cff-item').not('.cff-photolink-done').each(function(){
var $post = $(this),
urls = [];
$post.find('.cff-text a').each(function(){
var href = $(this).attr('href');
if (href && href.indexOf('facebook.com') == -1) urls.push(href);
});
$post.addClass('cff-photolink-done');
if (urls.length > 0) cffLinkPhoto($post.find('.cff-photo'), urls[0]);
});
}
cff_custom_js(jQuery);
</script>
If your feed is a Photos feed, the web address is in the caption of the photo instead. To handle that, use this snippet, which looks for the link in each caption.
<!-- Custom Facebook Feed JS -->
<script type="text/javascript">
function cff_custom_js($){
var $ = jQuery;
function cffDecode(text){
var box = document.createElement('textarea');
box.innerHTML = text;
return box.value;
}
$('.cff-album-item').not('.cff-photoalt-done').each(function(){
var $item = $(this),
$cover = $item.find('.cff-album-cover').first(),
alt = $cover.find('img').attr('alt'),
matchingUrl = '';
if (!alt) return;
$item.addClass('cff-photoalt-done');
$.each(cffDecode(alt).split(/\s+/), function(i, word){
if (word.indexOf('http') === 0 && word.indexOf('facebook.com') == -1) matchingUrl = word;
});
if (matchingUrl !== '') $cover.attr('href', matchingUrl);
});
}
cff_custom_js(jQuery);
</script>
Reverse the Order of Comments
This snippet reverses the comments under each post, so the newest comments show first. It then shows only as many comments as your feed is set to show, as the plugin does. The plugin loads the comments again a moment after the page loads, so the snippet watches for that and reverses them again. It works on feeds that show comments.
<!-- Custom Facebook Feed JS -->
<script type="text/javascript">
function cff_custom_js($){
var $ = jQuery;
$('#cff .cff-comments-wrap').not('.cff-reverse-done').each(function(){
var list = this,
$list = $(list),
show = parseInt($list.closest('.cff-comments-box').attr('data-num'), 10),
observer;
if (isNaN(show)) show = 4;
function reverseComments(){
var $comments = $list.children('.cff-comment');
if ($comments.length < 2) return;
$list.prepend($comments.get().reverse());
$list.find('.cff-comment').hide().slice(0, show).show();
}
$list.addClass('cff-reverse-done');
reverseComments();
observer = new MutationObserver(function(){
observer.disconnect();
reverseComments();
observer.observe(list, {childList: true});
});
observer.observe(list, {childList: true});
});
}
cff_custom_js(jQuery);
</script>
Add Dates to Photo, Video, and Album Feeds
Photo, album, and video grids show no dates. These snippets add one under each item. The month names are in English, and you can replace them with your own words in the months list.
For a Photos feed, use this snippet.
<!-- Custom Facebook Feed JS -->
<script type="text/javascript">
function cff_custom_js($){
var $ = jQuery;
function cffTimeConverter(unixTimestamp){
var a = new Date(unixTimestamp * 1000),
months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
return a.getDate() + ' ' + months[a.getMonth()] + ', ' + a.getFullYear();
}
$('.cff-album-item').not('.cff-photodate-done').each(function(){
var $item = $(this),
timestamp = $item.attr('data-cff-timestamp');
if (!timestamp) return;
$item.addClass('cff-photodate-done');
$item.append('<p class="cff-photo-date">' + cffTimeConverter(timestamp) + '</p>');
});
}
cff_custom_js(jQuery);
</script>
For an Albums or Videos feed, use this snippet instead. It adds the date to the info area of each item. That area shows only when the feed shows album names, album photo counts, or video names.
<!-- Custom Facebook Feed JS -->
<script type="text/javascript">
function cff_custom_js($){
var $ = jQuery;
function cffTimeConverter(unixTimestamp){
var a = new Date(unixTimestamp * 1000),
months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
return a.getDate() + ' ' + months[a.getMonth()] + ', ' + a.getFullYear();
}
$('.cff-album-item').not('.cff-albumdate-done').each(function(){
var $item = $(this),
timestamp = $item.attr('data-cff-timestamp');
if (!timestamp) return;
$item.addClass('cff-albumdate-done');
$item.find('.cff-album-info').append('<p class="cff-photo-date">' + cffTimeConverter(timestamp) + '</p>');
});
}
cff_custom_js(jQuery);
</script>
Change the Author Avatar Size
The author picture next to each post is 40 pixels wide by default. Two snippets make it larger.
The JavaScript asks Facebook for a larger picture. Change 150 to the size you want.
<!-- Custom Facebook Feed JS -->
<script type="text/javascript">
function cff_custom_js($){
var $ = jQuery;
$('.cff-author-img img').not('.cff-avatar-done').each(function(){
var $img = $(this),
src = $img.attr('src');
if (!src || src.indexOf('?') === -1) return;
$img.addClass('cff-avatar-done');
$img.attr('src', src + '&width=150');
});
}
cff_custom_js(jQuery);
</script>
The CSS then makes room for it. The 150px values must match the size in the JavaScript. The name and date stay next to the larger picture.
#cff .cff-author-img {
width: 150px;
height: 150px;
background: none;
border-radius: 50%;
}
#cff .cff-item .cff-author-img img {
width: 150px;
height: 150px;
border-radius: 50%;
}
Add Event Details to the Lightbox
In the Full width layout, the lightbox shows only the picture when a visitor opens an event photo. In the Thumbnail and Half width layouts, the plugin already shows the event details in the lightbox. This recipe adds the event title, date, place, and description beside it. It needs the lightbox turned on, and it works on events feeds.
To use it, follow these steps.
- First, make the event details available in the feed. To do this, go to Facebook Feed » All Feeds and edit your feed. Next, click Customize. Then click Posts and click Edit Individual Elements.
- Next, turn on Event Title and Event Details.
- Then, if you do not want the details to show in the feed as well, add the CSS below to Additional CSS.
- Finally, add the JavaScript below with WPCode.
This CSS hides the details in the feed, and they still show in the lightbox. It works in the Thumbnail and Half width layouts, where the details sit in their own box.
#cff .cff-event .cff-details {
display: none;
}
This JavaScript fills the caption of the lightbox with the details when a visitor clicks the picture. It waits a moment so the lightbox has opened first.
<!-- Custom Facebook Feed JS -->
<script type="text/javascript">
function cff_custom_js($){
var $ = jQuery;
$('#cff').off('click.cffEventDetails', '.cff-event .cff-photo').on('click.cffEventDetails', '.cff-event .cff-photo', function(){
var $event = $(this).closest('.cff-event'),
parts = [];
$.each(['.cff-event-title', '.cff-date', '.cff-location', '.cff-desc'], function(i, selector){
var content = $event.find(selector).first().html();
if (content) parts.push(content);
});
setTimeout(function(){
$('.cff-lightbox-caption-text').html(parts.join('<br />'));
}, 200);
});
}
cff_custom_js(jQuery);
</script>
The plugin has changed how the lightbox works since this recipe was first written. The release notes for version 4.15.0 say, “The lightbox now shows every item when you move through a feed with Next and Prev, and album thumbnails load again.” After you update the plugin, open an event photo to check that the details still show.
Link the Header to Your Facebook Page
The Text header type shows the words you type in its Text field as plain text with no link. This can be the name of your Page. This snippet makes a click on the header open your Page in a new tab. The Visual header already links to your Page with no code, so this recipe is only for the Text header.
To switch, go to Customize » Header in the feed builder and set Header Type to Text. Replace the web address in the snippet with the address of your own Page.
<!-- Custom Facebook Feed JS -->
<script type="text/javascript">
function cff_custom_js($){
var $ = jQuery;
$('.cff-header').not('.cff-headerlink-done').each(function(){
$(this).addClass('cff-headerlink-done').css('cursor', 'pointer').on('click', function(){
window.open('https://www.facebook.com/your-page-name', '_blank', 'noopener');
});
});
}
cff_custom_js(jQuery);
</script>
Remove Cover Photo Update Posts
When you change the cover photo of your Page, Facebook can add a post about it to your feed. This snippet removes any post that contains the text “updated their cover photo”. That text comes from Facebook in the language you set in the Localization setting. Change the words in the snippet if your feed uses another language.
<!-- Custom Facebook Feed JS -->
<script type="text/javascript">
function cff_custom_js($){
var $ = jQuery;
$('#cff .cff-item:contains("updated their cover photo")').remove();
}
cff_custom_js(jQuery);
</script>
Add a Pinterest Pin It Button
This recipe adds a Pin it button to the corner of each photo. It links each pin to the post on Facebook, so it needs the View on Facebook link to be on.
Turn off the lightbox first, so the lightbox does not catch the click on the button. To do this, go to Facebook Feed » All Feeds and edit your feed. Next, click Customize. Then click Lightbox and turn off the Enable switch.
<!-- Custom Facebook Feed JS -->
<script type="text/javascript">
function cff_custom_js($){
var $ = jQuery;
$('#cff .cff-item').each(function(){
var $item = $(this),
$photo = $item.find('.cff-photo').not('.cff-pin-done');
if ($photo.length < 1) return;
var pageUrl = $item.find('.cff-viewpost-facebook').first().attr('href') || window.location.href,
mediaUrl = $photo.find('img').attr('src') || '',
description = $item.find('.cff-text').text();
$photo.addClass('cff-pin-done');
$photo.prepend(
$('<a>', {
href: 'https://www.pinterest.com/pin/create/button/?url=' + encodeURIComponent(pageUrl) + '&media=' + encodeURIComponent(mediaUrl) + '&description=' + encodeURIComponent(description),
target: '_blank',
title: 'Pin it',
css: {position: 'absolute', top: '10px', left: '10px', 'z-index': 999}
}).append('<img src="//assets.pinterest.com/images/pidgets/pin_it_button.png" alt="Pin it" />')
);
});
}
cff_custom_js(jQuery);
</script>
More Layouts
Some layout changes need more than a snippet. Our guides below walk through them.
- Show your posts side by side in columns
- Change the font in your feed with Google Fonts
- Show your feed as a carousel
That’s it! You now have ready-made snippets to restyle your Facebook feed and to change how its posts, photos, comments, and events work. Next, see our guide to changing the font in your feed with Google Fonts, or the other guides in More Layouts. If a snippet does not behave as expected, check the questions below.
Frequently Asked Questions
Below, we’ve answered some of the most common questions about custom snippets in Facebook Feed.
Where do I put the CSS and the JavaScript?
CSS goes in Additional CSS under Appearance, then Customize, in your WordPress dashboard. JavaScript goes in a code snippets plugin such as WPCode. See Where to Add Your Code at the start of this guide for the steps and the guides that cover each one.
Why does my JavaScript snippet do nothing?
First, check that the feed shows the part the snippet changes. For example, the comments recipes need comments to be on, and the event recipes need an events feed. Also check that the snippet sits inside the template shown at the start of this guide. Then check that your caching or speed plugin is not delaying the script. Then use Inspect on the post to confirm the class names match.
Do the snippets still work after I click Load More?
Yes, as long as all your JavaScript recipes are in one snippet. The plugin runs your JavaScript again after each Load More. The recipes that add or move something mark each post they have changed, so a post is never changed twice.
Can I use more than one JavaScript recipe at once?
Yes. Put them in one snippet with a single copy of the template, as described in Where to Add Your Code. If each recipe sits in its own snippet, they all run when the page loads, but only the last one runs again after Load More.
How do I find the ID or the author class of a post?
Right-click the post on your page and click Inspect. The opening tag of the post shows its ID, which starts with cff_, and its classes, which include one that starts with author-.
Will a snippet keep working after I update the plugin?
Yes, as long as the plugin keeps the class names the snippet uses. A plugin update that renames a class or moves an element can affect a snippet. After an update, check the pages where you use a snippet.