[Resolved] Hide updated date

Home Forums Support [Resolved] Hide updated date

Home Forums Support Hide updated date

  • This topic has 13 replies, 3 voices, and was last updated 4 years ago by David.
Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #1208604
    Nacho

    Hello Tom,

    How do you hide the updated date when the has just been published and there is no update?

    I have this CSS code:

    .posted-on .updated {
        display: inline-block;
    }
    
    .posted-on .published:before {
        content: "Publicado el ";
    }
    .posted-on .updated:before {
        content: "Actualizado el ";
    }
    
    .posted-on {
        display: inline-flex;
    }
    
    .entry-date {
        order: -1;
        margin-right: 10px;
        border-right: 1px solid #ddd;
        padding-right: 10px;
    }

    I want to show the updated date when it´s been updated but no when it´s just been published.

    Thanks a lot.

    #1208680
    Leo
    Staff
    Customer Support
    #1208866
    Nacho

    Hello Leo,

    I´ve just inserted that code but know the published date is shown twice.

    Is this fixable?

    Thanks a lot.

    #1208900
    Leo
    Staff
    Customer Support

    Can you remove your own CSS first?

    Let me know 🙂

    #1208917
    Nacho

    Hi Leo,

    Sure, I´ve just did it.

    Also, I´ve changed the URL to other one so we can run the tests in the website that is for testing purposes.

    Let me know.

    Thanks a lot.

    #1208921
    Nacho

    Hi Leo,

    I did not say it but if we need to show both the published date and the updated date when those are in different dates but if there is no updated date, just show the published date.

    Thanks a lot.

    #1208922
    Leo
    Staff
    Customer Support

    Just to confirm, this PHP snippet is all you are using right now?
    https://generatepress.com/forums/topic/hide-modified-date-if-is-the-same-as-posted-date/#post-1199125

    I just tested it and it seems to work by default without any CSS added.

    #1208924
    Nacho

    Hi Leo,

    Yes, that one and without the CSS.

    As you can see in the image, it´s showing the published date twice: https://d.pr/i/EmHyFp

    Thanks.

    #1209032
    Leo
    Staff
    Customer Support

    Do you happen to have any other filters or functions added related to meta?

    The code is working for me like this:
    https://wordpress-202309-991531.cloudwaysapps.com/2020/03/23/test-post/
    https://wordpress-202309-991531.cloudwaysapps.com/2020/03/25/test-3/

    #1209172
    Nacho

    Hello Leo,

    I have this one below that deactivates the links in the dates:

    add_filter( 'generate_post_date_output','tu_remove_date_link', 10, 2 );
    function tu_remove_date_link( $output, $time_string ) {
    	printf( '<span class="posted-on">%s</span>',
    		$time_string
    	);
    }

    Deactivating that filter it seems to be working but I want to get rid off the link for the date. How can I have both?

    Hope it helps.

    Thanks a lot.

    #1209180
    Nacho

    Hello Leo,

    It seems to be working fine with just that filter. Now the problem is that it looks weird on mobile.

    With just the CSS you´ve provided it looks super fine, dates in two columns but with the filter it does not even with both filter and the CSS.

    The code with the filter + CSS is like this:

    Filter:

    add_filter( 'generate_post_date_output', function( $output, $time_string ) {
        $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Publicado el: %2$s</time>';
    
        if ( get_the_date() !== get_the_modified_date() ) {
            $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Publicado el: %2$s</time><time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified">Actualizado el: %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 );

    CSS:

    .entry-date.published {
        order: -1;
        margin-right: 10px;
        border-right: 1px solid #ddd;
        padding-right: 10px;
    }

    Here is the screenshot with the CSS: https://d.pr/i/9XH6F0 and here with the filter + CSS: https://d.pr/i/RdgidR

    Is there a way to have the filter one looking like if I was using the CSS?

    Thanks a lot.

    #1209469
    David
    Staff
    Customer Support

    Hi there,

    try adding this CSS:

    .posted-on {
        display: flex;
    }
    #1209535
    Nacho

    Hello David,

    That worked like charm.

    Thanks a lot for your help!

    Have a nice day.

    #1209784
    David
    Staff
    Customer Support

    Glad we could be of help

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