Back to blog

Output Dynamic Dates for Your Websites

Mike

It’s important to make sure your website speaks the same language as search engines and screen readers, for multiple reasons. There are tons of HTML elements we can use when developing our websites, the <time> tag is one of them!

The <time> HTML element represents a specific period in time. It may also include the datetime attribute to translate dates into a machine-readable format, allowing for better search engine results, as mentioned above.

A <time> tag showing the datetime attribute rendered on the frontend.

We can actually do this with our Bricks Builder websites using the power of dymanic data!

So, how does it work?

As an example, when we create a query loop to show a list of our blog posts, we can use the Basic Text element and the { post_date } dynamic data field to render the date of each specific blog post.

In this case we renamed our Basic Text element ‘Date’, as this makes it easier to locate and understand in the structure panel. We encourage you to do the same (in your own language, of course).

Using the <time> HTML tag

By default the Basic Text element’s HTML tag is a div but, Bricks Builder allows us to change this by clicking the select field. The select dropdown will show a number of popular selections, but for this scenario we need to select ‘custom’. By selecting ‘custom’, the GUI then populates an empty field below so that we can now type our own custom tag, which in this case is ‘time’.

A Basic Text element with a <time> custom HTML tag.

This will now beautifully wrap your blog post dates in a <time> tag, rather than a standard <div> tag. Wicked!

Using the datetime attribute

We can also go a step further and make search engines really love our content. We can do this by adding a datetime attribute to our <time> tag.

To do this, go to the Style tab of your Basic Text element and scroll right down to the bottom, here you’ll see the ‘Attributes’ settings. To add your datetime attribute just follow the three simple steps below:

  1. Click ‘+ Add Attributes’.
  2. In the ‘Name’ field, type ‘datetime’.
  3. In the ‘Value’ field, type ‘post_date:Y-m-d’ inside your curly braces {}.
Attribute settings showing the correct format for the datetime.

Using the same { post_date } tag will produce the same date as the <time> HTML tag (depending on what date format you decide to chose in your WordPress General Settings). We can expand on this to ensure we are using the correct datetime values by adding ‘:Y-m-d’ at the end.

Once you’ve done this, you can now save your page and view your work on the frontend. You will now see within each blog post inside your query loop, that the date will be wrapped in a <time> tag, and it will also have the datetime attribute showing the correct date formate for that specific post.

Now you have consistent & accessible, semantic markup for your dates! 😎

Share this article:

Speed up your development

Bricks Library is home to 1100+ cutting-edge templates to help you build awesome websites in rapid time!

Get started

✨ Brand-new update

  • Buttons, Blog Posts and a whole lot more…

  • Sao Paulo Layout