Site logo

Archived topic

Hide updated date

13 replies · Started by Nacho on March 24, 2020

Viewing posts 1–14 of 14

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.

Hello Leo,

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

Is this fixable?

Thanks a lot.

Can you remove your own CSS first?

Let me know :)

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.

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.

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.

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.

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.

Hi there,

try adding this CSS:

.posted-on {
    display: flex;
}

Hello David,

That worked like charm.

Thanks a lot for your help!

Have a nice day.

Glad we could be of help

This archived topic is closed to new replies.