Site logo

[Resolved] Add ‘Last updated’ date to blog posts

Home Forums Support [Resolved] Add ‘Last updated’ date to blog posts

Home Forums Support Add ‘Last updated’ date to blog posts

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #2012916
    crosby87

    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.

    #2013046
    David
    Staff
    Customer Support

    Hi there,

    do you want the Header Element to only display one date ? ie. the published or last updated if it exists… if so try the snippet here:

    https://docs.generatepress.com/article/show-the-updated-post-date/#show-the-“updated”-post-date-in-header-element

    #2013459
    crosby87

    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]

    #2013613
    Ying
    Staff
    Customer Support

    Hi there,

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

    #2014105
    crosby87

    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?

    #2015486
    crosby87

    Hi there,

    Seems this was missed. Thanks

    #2015583
    Ying
    Staff
    Customer Support

    That is the default post meta, you should be able to disable it in customizer > layout > blog > content > single, uncheck the display post date option.
    https://docs.generatepress.com/article/blog-content-layout/#single

    #2015612
    crosby87

    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

    #2015770
    Ying
    Staff
    Customer Support

    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?

    #2015775
    crosby87

    Sorry, now fixed. No longer has.

    #2015866
    Ying
    Staff
    Customer Support

    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 🙂

    #2015907
    crosby87

    works perfectly, many many thanks!

    #2015948
    Ying
    Staff
    Customer Support

    You are welcome 🙂

    #2020649
    Lucie

    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.

    #2020652
    Elvin
    Staff
    Customer Support

    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; }

Viewing 15 posts - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.