A reference for building a custom feed date format, with examples and what each format letter represents.
Would you like to change how dates look in your Facebook feed?
Facebook Feed lets you pick a built-in date format or write your own.
This guide shows where the date settings are and how the built-in formats work. It also lists the letters you can use in a custom format and shows how to stack an event date in Facebook Feed Pro.
Before you get started, make sure Facebook Feed is installed and activated on your WordPress site.
- Choosing a Built-In Date Format
- Writing a Custom Date Format
- Date Format Letters
- Hiding the Event End Date
- Stacking an Event Date
- Frequently Asked Questions
Choosing a Built-In Date Format
To get started, we’ll open the date settings of your feed in the feed builder.
- First, go to Facebook Feed » All Feeds in your WordPress dashboard and open the feed you want to change.
- Next, click the Customize tab. Then click Posts.
- Then, click Edit Individual Elements. Next, click Date.
- Finally, under Format, open the drop-down list and pick a format. Each date option shows the same sample date written in that format.
A new feed starts with the first option, “2 days ago”. It shows how long ago each post went up, so visitors can see at a glance how fresh your feed is. The other options show the date itself, in styles such as the month and day, the full weekday, or numbers only. Your choice changes how the date looks on every post in the feed.
The words in “2 days ago” come from the Translation tab of the plugin settings, so you can show them in your site’s language or in your own wording. To change them, follow these steps.
- First, go to Facebook Feed » Settings in your WordPress dashboard.
- Next, click the Translation tab.
- Then, edit the text boxes for the time words, such as days, hours and ago.
- Finally, save your changes.
If you use an Events feed in Facebook Feed Pro, the event date has its own settings. To find them, follow these steps.
- First, open your Events feed in the feed builder and click the Customize tab.
- Next, click Posts. Then click Edit Individual Elements.
- Finally, click Event Date.
The Event Date Format list works the same way, with its own set of built-in formats, most of which show the time as well. A new Events feed starts on the first option, which shows a date like “Jul 25, 5:30pm”.
Writing a Custom Date Format
If none of the built-in formats fits, you can write your own. A custom format is a short line of letters. Each letter stands for one part of the date. For example, the letter F stands for the full month name.
- First, open the Format list in the Date section, or in the Event Date section of an Events feed.
- Next, choose Custom. A text box appears under the list.
- Then, type your format in the box. The box shows
Eg. F j, Yas an example. - Finally, click Save at the top of the builder.
Below the Format list, the builder shows a “Learn more about custom formats” link that points to this guide. The plugin passes your format to the WordPress date_i18n() function. WordPress translates month and weekday names into your site’s language when that language has them.
A format uses the same letters as the PHP date format characters. Any other character, such as a space, a comma or a dash, shows up as you typed it.
Here are a few examples. Each one shows what the format gives for 5:30 pm on July 25, 2013.
F jS, g:i ashows July 25th, 5:30 pmF jSshows July 25thD F jSshows Thu July 25thl F jSshows Thursday July 25thD M jS, Yshows Thu Jul 25th, 2013l F jS, Yshows Thursday July 25th, 2013l F jS, Y - g:i ashows Thursday July 25th, 2013 – 5:30 pml M jS, yshows Thursday Jul 25th, 13m.d.yshows 07.25.13m/d/yshows 07/25/13
Date Format Letters
To build your own format, use the letters below.
Time
ashows am or pm, in lowercase.Ashows AM or PM, in uppercase.gshows the hour without a leading zero, from 1 to 12.Gshows the hour in 24-hour format without a leading zero, from 0 to 23.hshows the hour with a leading zero, from 01 to 12.Hshows the hour in 24-hour format with a leading zero, from 00 to 23.ishows the minutes with a leading zero, from 00 to 59.sshows the seconds with a leading zero, from 00 to 59.
Day
dshows the day of the month with a leading zero, from 01 to 31.jshows the day of the month without a leading zero, from 1 to 31.Sshows the two-letter English ending for the day of the month (st, nd, rd or th). It works well afterj.Dshows the weekday in three letters, from Mon to Sun.lshows the full weekday name, from Sunday to Saturday. This is a lowercase L.wshows the weekday as a number, from 0 for Sunday to 6 for Saturday.zshows the day of the year, counting from 0, so the values run from 0 to 365.
Month
mshows the month as a number with a leading zero, from 01 to 12.nshows the month as a number without a leading zero, from 1 to 12.Mshows the month in three letters, from Jan to Dec.Fshows the full month name, from January to December.tshows the number of days in the month, from 28 to 31.
Year
Lshows 1 for a leap year and 0 for any other year.Yshows the year in four digits.yshows the year in two digits, from 00 to 99.
Hiding the Event End Date
Events feeds are part of Facebook Feed Pro. When an event has an end date, the plugin shows it after the start date.
With a built-in event date format, the plugin hides the part of the end date that repeats the start date when the event ends on the same day that it starts. Instead of “June 1st, 5pm – June 1st, 9pm”, the feed shows “June 1st, 5pm – 9pm”.
With a custom format, you choose which part of the end date to hide. To do that, wrap that part in the {hide-start} and {hide-end} tags. Here is an example.
{hide-start}F jS, {hide-end}g:i a
In the end date, the plugin hides the text between the two tags when it matches the same part of the start date. In the example, the end date drops “June 1st,” and keeps the time. To make this work, put only the date inside the tags and leave the time outside. If the time sat inside the tags too, it would almost never match the start time. The end date would then always show in full.
Stacking an Event Date
You can stack the parts of an event date, so the weekday, day, month and year sit in a column in place of the event picture. There are two versions. One shows only the day and the month. The other shows the whole date. Both need an Events feed in Facebook Feed Pro, a little CSS and a little JavaScript.
The recipes work when the feed’s post layout is Thumbnail. To set it, follow these steps.
- First, open your Events feed in the feed builder and click the Customize tab.
- Next, click Posts.
- Then, under Layout, choose Thumbnail.
- Finally, click Save at the top of the builder.
Add the CSS to the Additional CSS box in WordPress, as shown in our guide to using custom CSS code in our plugins. Add the JavaScript to WPCode, as shown in our guide to moving custom JavaScript code out of our plugins. The JavaScript uses the snippet template from that guide.
When the Load More button loads more posts, the plugin runs the cff_custom_js function again. For that reason, each snippet below marks an event as done, so it never changes the same event twice.
Showing Just the Day and the Month
- First, open Edit Individual Elements in your Events feed and click Event Date.
- Next, open the Format list and choose the first option. It shows a date like “Jul 25, 5:30pm”. The snippet below reads the month and the day from this format.
- Then, click Save at the top of the builder.
Next, add this JavaScript in WPCode.
<!-- Custom Facebook Feed JS -->
<script type="text/javascript">
function cff_custom_js($){
var $ = jQuery;
$('.cff-event').not('.cff-stacked').each(function(){
var $self = $(this).addClass('cff-stacked'),
cff_sd_arr = $self.find('.cff-start-date').text().split(' ');
$self.find('.cff-start-date').html('<span class="cff-month">' + cff_sd_arr[0] + '</span><span class="cff-day">' + cff_sd_arr[1].replace(/,/g, '') + '</span>');
$self.find('.cff-photo').html($self.find('.cff-date')).removeAttr('href').css('cursor', 'default');
});
}
cff_custom_js(jQuery);
</script>
Finally, add this CSS in Additional CSS.
#cff .cff-start-date, #cff .cff-month, #cff .cff-day { display: block; }
#cff .cff-start-date { text-align: center; }
#cff .cff-end-date, #cff .cff-more-dates, #cff .cff-multiple-dates, #cff .cff-lightbox-link { display: none !important; }
#cff .cff-month { font-size: 20px; }
#cff .cff-day { font-size: 30px; }
The date now sits in the place of the event picture, with the month above the day.
Showing the Entire Date
- First, open Edit Individual Elements in your Events feed and click Event Date.
- Next, open the Format list, choose Custom and type the format below in the box that appears. The tags keep the date apart from the time. This lets the snippet find it. After you type the format, click Save at the top of the builder.
{hide-start}D j M Y{hide-end}g:iA
Then, add this JavaScript in WPCode.
<!-- Custom Facebook Feed JS -->
<script type="text/javascript">
function cff_custom_js($){
var $ = jQuery;
$('.cff-event').not('.cff-stacked').each(function(){
var $self = $(this).addClass('cff-stacked'),
$date = $self.find('.cff-start-date k'),
cff_sd_arr = $date.text().split(' ');
$date.html('<span class="cff-dayweek">' + cff_sd_arr[0] + '</span><span class="cff-day">' + cff_sd_arr[1] + '</span><span class="cff-month">' + cff_sd_arr[2] + '</span><span class="cff-year">' + cff_sd_arr[3] + '</span>');
$self.find('.cff-photo').html($date).removeAttr('href').css('cursor', 'default');
});
}
cff_custom_js(jQuery);
</script>
Finally, add this CSS in Additional CSS.
#cff .cff-dayweek { font-size: 30px; }
#cff .cff-day { font-size: 50px; }
#cff .cff-month { font-size: 25px; }
#cff .cff-year { font-size: 20px; }
#cff .cff-photo k, #cff .cff-photo k span { display: block; }
#cff .cff-photo k { line-height: 1; text-transform: uppercase; text-align: center; }
#cff .cff-end-date k, #cff .cff-more-dates, #cff .cff-multiple-dates, #cff .cff-lightbox-link { display: none !important; }
The weekday, day, month and year now stack in the place of the event picture.
That’s it! You now know how to choose a date format, write your own and stack an event date. For more custom code you can copy, see our Facebook Feed custom snippets guide.
Frequently Asked Questions
Below, we’ve answered some of the most common questions about date formats in Facebook Feed.
How do I show a date like “2 days ago”?
To do this, open the Format list in the Date section of your feed and choose the first option, “2 days ago”. A new feed starts with it. To change its words, see the Choosing a Built-In Date Format section above.
Can posts and events use different date formats?
Yes. The Date section sets the format for posts, and the Event Date section of an Events feed sets the format for events. Each has its own Format list and its own Custom box.
Will the month and weekday names show in my site’s language?
The plugin passes your format to the WordPress date_i18n function. WordPress translates month and weekday names when your site’s language has them. Letters that show numbers, such as j and Y, look the same in every language. For the “2 days ago” format, the words come from the Translation tab, where you can type them in your language.
Why does my event end date show the whole date again?
The plugin hides part of the end date only when the part inside the hide tags, or the date part of a built-in format, matches the start date. If the event ends on a different day, the end date shows in full. With a custom format, check that the hide tags wrap only the date and not the time.
Do the hide tags work in the free version?
No. Events feeds and the hide tags are part of Facebook Feed Pro. The free version has the Date section, the built-in formats and the custom format letters.