Docs    Instagram    Customizations

Change the date format displayed when hovering over a post

A functions file snippet that changes the hover date format on a feed without affecting page speed.

Would you like to change the date format that shows when you hover over a post in your Instagram feed?

Before you get started, Instagram Feed Pro must be installed and activated on your WordPress site. The hover date is part of Instagram Feed Pro, so the steps below apply to that plugin.

Showing the Date on Hover

By default, the hover date shows the month and the day, such as Feb 2. A small PHP snippet can show a different format, such as one that adds the year. First, the date must be set to show on hover.

  1. In the feed editor, go to Customize » Posts » Hover State.
  2. Under Information to display, check Date. For the other hover options, see our guide on changing the hover state.

Next, we’ll add the snippet.

Adding the Snippet

The snippet below adds the year to the hover date, such as Feb 2 2020. It uses the sbi_posted_on_date filter, which lets custom code change the date text. The plugin passes the filter two values. The first is the date as text, in the default format. The second is the post’s timestamp. The snippet builds the new date from the timestamp, so the year is always right.

function sbi_custom_date( $posted_on_date_str, $timestamp ) {
	return ucfirst( date_i18n( 'M j Y', $timestamp ) ); // ex. Feb 2 2020
}
add_filter( 'sbi_posted_on_date', 'sbi_custom_date', 10, 2 );

The M j Y part is the format. To use a different one, change it to any date format. For the format characters, see the WordPress guide to customizing the date and time format.

The same date text can also appear elsewhere in your feed, depending on your feed theme. The new format applies there too.

We recommend adding the snippet with WPCode, a free plugin that keeps your custom code in one place.

  1. Install and activate the WPCode plugin. Then, go to Code Snippets » Add Snippet.
  2. Next, hover over the box named Add Your Custom Code (New Snippet). Then, click + Add Custom Snippet.
  3. In the window that opens, choose PHP Snippet.
  4. Next, type a title for your snippet, such as Instagram hover date format. Then, paste the snippet into the code box. The box already starts with an opening PHP tag, so don’t add one of your own.
  5. At the top of the page, click the toggle to switch the snippet from Inactive to Active.
  6. Finally, click Save Snippet.

If you’d rather not use WPCode, the snippet can also go in your theme’s functions.php file. A theme update can remove it from there. That is why we suggest WPCode.

Now, open a page that shows your feed and hover over a post. The date shows in your new format.

That’s it! Your feed now shows the hover date in the format you chose.

Next, see how the WPCode integration works to browse ready-made snippets for your feeds.

support

Couldn’t find your answer in the docs?

Contact Support