Replace Published Date with Last Updated Date

Hi Team,
How do I replace Published Date with Last Updated Date
currently all the posts on main page and each post show date in this format
by [Couple of Steps] September 10, 2020
How do I make it
Last Updated September 10, 2020 by [Couple of Steps]

Easiest would be to use Loco translate and change it in there.

Hi,

Thank you for reaching out to us. And I am sorry for the delayed response.

Try adding this CSS code to your website’s Additional CSS.

    .posted-on .updated:not(.published) {
      display: inline;
    } 

    .posted-on .published:not(.updated) {
      display: none;
    }

Regards,
Kharis
aThemes Support

Hi @kharisblank

Thank you for your reply, This code got rid of posted date and replaced it with modified date. But how do I change the UI ?

currently all the posts on main page and each post show date in this format
by [Couple of Steps] September 10, 2020
How do I make it
Last Updated September 10, 2020 by [Couple of Steps]

Hi,

Thank you for getting back.

To accomplish this, you’ll need to edit the theme’s cali_posted_on() function by overriding it from a child theme’s functions. For example, add this snippet to your child theme’s functions.php file.

	function cali_posted_on() {
		$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
		if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
			$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%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() )
		);

		$posted_on = sprintf(
			__('Last Updated <a href="%1$s" rel="bookmark">%2$s</a>', 'post URL', 'last updated date', 'cali'),
			esc_url( get_permalink() ),
			$time_string
		);

		$byline = sprintf(
			/* translators: %s: post author. */
			esc_html_x( 'by %s', 'post author', 'cali' ),
			'<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'
		);

		echo '<span class="posted-on">' . $posted_on . '</span> <span class="byline"> ' . $byline . '</span>'; // WPCS: XSS OK.

	}

Adding, you may want to consult to this documention to get to know about child theming, just in case you haven’t yet been running any child theme.

I hope this reply helps.

Regards,
Kharis
aThemes Support

1 Like

@kharisblank
Thank you for the solution, I will try the child theme over the weekend but until then found a workaround and for people who don’t want to touch main theme code you can try this too

  .posted-on .updated:not(.published) {
    display: inline;
  }
  .posted-on .published:not(.updated) {
    display: inline;
  }

  .posted-on .updated:before {
    content: " | Last updated: ";
    position: relative;
  }

Output :

1 Like