Site logo

Archived topic

Add 'Last updated' date to blog posts

14 replies · Started by crosby87 on November 21, 2021

Viewing posts 1–15 of 15

Hi there,

I have previously added the options to show 'Last updated' date for my blog posts in case there was an update since the original posting.
However, for some of my blog posts this does not appear. I think it has to do with the change in the heading that I have made.

I have the following code in the heading of the article where it is not appearing (among others):

<h1>
	{{post_title}}
</h1>

<div class="hero-meta">
	{{post_author}} | {{post_date}}
	{{custom_field.name}}
</div>

Could you please help? See links in private below.

Hi there,

Thanks.

When I added the code below it added the date to a strange place. Please see the screenshot, circled: https://imgur.com/qieqL06

I have added the following code, as shown on David's comment above:

function post_modified_date() {
    return get_the_modified_date();
}
add_shortcode( 'modified_date', 'post_modified_date' );

I have now removed the code, because I cannot leave it like that for long.

1. Could you please help fix that?
2. Where exactly do I need to add this? [modified_date]

Hi there,

You can use Last updated: [modified_date] to replace {{post_date}} in your header element.

Hi Ying,

Thanks. I have added, but like I said before, there's an additional date popping up in my content:https://imgur.com/qieqL06

Please see it circled. I have added my date to the header (see link in private), but the circled one appears IN ADDITION.

How can I remove that?

Hi there,

Seems this was missed. Thanks

Ying,

If I do that then the date will no longer appear on my other blog posts.

Like I said, I have two types of blog posts.
1) the normal looking ones where I still want the date to appear (see example links in private)
2) the ones where the header is modified and to which I now added the code referred to earlier by David

The 2 links you provided both have a header element:
https://www.screencast.com/t/pE1ey1wFdaLP

In order to provide solution, I need to know what's the differences between these 2 type of posts? Are they in different category?

Or one of them should have NO header element applied?

Sorry, now fixed. No longer has.

I'm still seeing the header element, maybe a cache issue.

Can you give this CSS a try:

.single-post .page-hero ~ .site .entry-header > .entry-meta {
    display: none;
}

Let me know :)

works perfectly, many many thanks!

You are welcome :)

Very useful thread, thank you. Follow up question, is it possible to use {{modified_date}} as a template tag (in the context of adding a New Element of type Header? I ask, because I can use {{post_date}} template tag, just wondering if I can just use {{modified_date}} instead of some of the other less elegant options listed above. Thanks in advance.

Hi Lucie,

Shortcode usage was suggested because there's no template tag exactly for modified date.

{{post_date}} actually adds in an element for modified date but hides it by default. In a sense, you can use it to serve as the modified date template tag as well.

You can make it appear with this CSS: .page-hero time.updated { display: block; }

Or if you want to use {{post_date}} for both modified date and post date then you have to wrap the template tag with a selector so you can specify which one will display the modified tag.

Example HTML:

<span class="modified-date-tag">
{{post_date}}
</span>

<span class="post-date-tag">
{{post_date}}
</span>

With this HTML structure, we can turn the {{post_date}} tag under modified-date-tag to display the modify date using this CSS:

.page-hero span.modified-date-tag time.updated { display: block; }

This archived topic is closed to new replies.