[Resolved] Hide modified date if is the same as posted date

Home Forums Support Hide modified date if is the same as posted date

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1198147
    Ingrid

    Hello!
    First of all I want to say I love Generate Press,its an awesome theme!

    So, I want to show the modified date in my posts, I did that by using the CSS I found in this post
    But if I post something and modify it in the same day it shows like this:

    Modified on 18 march 2020 / Posted on 18 march 2020

    is it possible to hide the modified date if the posted date is the same?

    I am using the latest Generate Press premium
    Thanks in advance!

    #1198573
    Leo
    Staff
    Customer Support
    #1198629
    Suraj Katwal

    I have been using this code in my site

    add_filter( 'generate_post_date_output', function( $output, $time_string ) {
        $time_string = 'Published on: %2$s';
    
        if ( get_the_date() !== get_the_modified_date() ) {
            $time_string = 'Last Updated on: %4$s';
        }
    
        $time_string = sprintf( $time_string,
            esc_attr( get_the_date( 'c' ) ),
            esc_html( get_the_date() ),
            esc_attr( get_the_modified_date( 'c' ) ),
            esc_html( get_the_modified_date() )
        );
    
        return sprintf( '%s ',
            $time_string
        );
    }, 10, 2 );

    It will show the Published on: date if updated the content on the same day and Last Update on: if you update on another day.
    I think David shared this code somewhere and I have implemented it on my blog.

    SEO, WordPress Optimization, Blogging Tutorials.
    GeneratePress Tutorial: https://www.wplogout.com

    #1198645
    Ingrid

    This code helps a lot but I would want to show the published date too, like this:
    published on 10 march 2020 / updated on 18 march 2020

    and if the date of publishing and editing are the same then just the published date:
    published on 10 march 2020

    #1198934
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    It shouldn’t print the updated date unless it’s different than the published date. Are you using a function/CSS as of right now? Any chance you can link us to a post?

    #1199077
    Suraj Katwal

    Hi Tom,
    Here is what David Replied to me Last Updated Date and here is what I have been using in my GeneratePress to Display Last Updated Date and Published Date

    Thank you

    SEO, WordPress Optimization, Blogging Tutorials.
    GeneratePress Tutorial: https://www.wplogout.com

    #1199125
    Ingrid

    Hi guys, I modified a bit the code that Suraj Katwal linked to, it worked for me! Now it shows the published and modified date,and if the post was modified the same day is shows just the published date:

    
    add_filter( 'generate_post_date_output', function( $output, $time_string ) {
        $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>';
    
        if ( get_the_date() !== get_the_modified_date() ) {
            $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">published on: %2$s</time> / <time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified">Last Updated on: %4$s</time>';
        }
    
        $time_string = sprintf( $time_string,
            esc_attr( get_the_date( 'c' ) ),
            esc_html( get_the_date() ),
            esc_attr( get_the_modified_date( 'c' ) ),
            esc_html( get_the_modified_date() )
        );
    
        return sprintf( '<span class="posted-on">%s</span> ',
            $time_string
        );
    }, 10, 2 );
    

    Thanks a lot for the help!

    #1199712
    Tom
    Lead Developer
    Lead Developer

    Awesome, thanks for sharing your code! 🙂

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