Skip to content

Translating "Days Ago" via %s Variable and Setting Correct WordPress Site Language

Control how the elapsed-time date on your ads, blog posts and quick view reads: put your own wording around the %s variable, and let WordPress translate the time units themselves.

2 minute read

This article focuses on how to translate texts in your single ads template, blog posts, quick view, and many other modules that show the time elapsed since a particular post or ad was added to your website.

A single ad page for a yellow toy truck titled "Wallie toy", where the highlighted date line under the photo reads "2 years ago" next to 1082 Views.

This text function is based on default WordPress functionality, and as theme authors, we do not duplicate functions that already exist. This text can appear in various forms, displaying when an ad was added, for example:

  • 3 hours ago
  • 6 days ago
  • 3 months ago
  • 2 years ago

Change the wording around the date

To translate these texts, visit Listivo Panel > Translate & Rename and search for the "%s ago" text string. %s is a variable that represents a number followed by a time period (e.g. 3 hours, 3 days, 3 months, 3 years), and you can place it anywhere in the text to adapt it to your language preferences. You can add text before and after it, as shown below by placing the variable in the appropriate place.

The Translate & Rename screen with the Strings tab open, where the "%s ago" string has been filled in with "text before %s text after". The sidebar menu reads Listivo Panel.

The configuration as above will result in displaying dates like this:

The same ad page, where the date line now reads "text before 2 years text after".

Translate the time units themselves

The time units come from WordPress, not the theme
Text such as "2 years" (or months, days, hours) cannot be translated in Translate & Rename, because it comes directly from the WordPress site translation.

If you use Spanish, for example, make sure your website's Site Language is set to Spanish in wp-admin > Settings > General.

The WordPress Settings > General screen with the Site Language dropdown set to Español.

This will automatically translate all "years," "months," etc., text strings to your language.

The ad date line now reading "text before 2 años text after", with the Spanish "2 años" highlighted.

Ask the people who build MyHome

We answer by email from support@tangiblewp.com. With Premium Support, we also fix your site when something breaks.

Was this guide helpful?