Support » Theme: Pure & Simple » How to show ‘Last Update’ date for posts instead of ‘Published’ date?

  • Resolved philip2041

    (@philip2041)


    Hello,

    I want to make my blog show ‘Last Update’ date instead of ‘Published’ date for my blog posts, as I found publish date of blog posts is shown on Google search result pages, this may not good for posts that are published years ago, as people don’t want to read old articles.

    So I want to change the text “published on …” under the blog title to “updated on…”, and whenever I update a post, the date of the post will get updated.
    And I want the date to be shown on both blog post and search engine result page.

    A perfect example is the site Lifewire.com, all of its blog posts only show update date, and the update date is also shown on Google search result page instead of showing published date.

    I tried to directly change the date at a dedicated section in the right sidebar of the post edit panel, and replace the code for the text ‘published on’ with ‘updated on’, but in that way my old post will be moved to the first row of the blog loop when I update it, I don’t want that, I just want the date be updated but let it remain in the original position in the blog loop.

    So can anybody help me figure out a way to achieve this? Thanks in advance!

    Below is the related code I found in content-single.php and template-tags.php, I’m a beginner on coding, so I don’t know how to tweak these code to achieve what I want.

    <div class="entry-meta">
    			<?php puresimple_posted_on(); ?>
    </div><!-- .entry-meta -->
    
    function puresimple_posted_on() {
    	$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
    	if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
    		$time_string .= '<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(
    		__( 'Published on %s', 'pure-simple' ),
    		'<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
    	);
    
    	$byline = sprintf(
    		_x( 'by %s', 'post author', 'pure-simple' ),
    		'<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>';
    • This topic was modified 3 months, 1 week ago by  philip2041.
Viewing 10 replies - 1 through 10 (of 10 total)
  • I think maybe this will work, but I’m not sure:

    Replace

    <div class="entry-meta">
    	<?php puresimple_posted_on(); ?>
    </div><!-- .entry-meta -->

    with

    <div class="entry-meta">
           echo 'Updated on:' . the_modified_date() ;
     </div><!-- .entry-meta -->
    Theme Author Styled Themes

    (@gejay)

    Hello @philip2041,

    Just replace as you stated above with;

    <div class="entry-meta">
         <?php _e( 'Updated On ', 'pure-simple' );  the_modified_date() ; ?>
    </div>

    Thanks!

    philip2041

    (@philip2041)

    Hello @gejay,

    Thank you so much for the reply! I will try the code you gave me.

    philip2041

    (@philip2041)

    Hi @gejay ,

    The code you gave me does can make the post show “Updated On mm/dd/yyyy” under the title.

    However, as I checked with browser’s inspect element tool, the original “Published on mm/dd/yyyy” has <time> tag wrapped on the date, but now the “Updated On mm/dd/yyyy” is just plain text.

    So will the date still be shown on search engine result page? My main purpose is to make the updated date to show on the search engine result page, but I don’t know how search engines determine and display the date of a post, is that <time> tag important?

    Thanks!

    Theme Author Styled Themes

    (@gejay)

    Hello @philip2041,

    Here’s a tweak you can make;
    1. Undo the changes inside content-single.php
    1. Add the following CSS inside Customize>>Additional CSS;

    .single-post time.entry-date.published {
        display: none;
    }
    .single-post time.updated {
        display: inline;
    }

    2. Go to pure-simple/inc/template-tags.php and modify Published On to Updated On as follows;
    Inside function puresimple_posted_on() {....}

    $posted_on = sprintf(
    		__( 'Updated on %s', 'pure-simple' ),
    		'<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
    	);

    Note: You can build the template tag of your own. We don’t recommend you to make changes in the parent theme unless you’re updating the theme or applying hooks in child theme. It’s because the changes lost upon further theme updates.

    Thanks!

    philip2041

    (@philip2041)

    Hi @gejay ,

    The above measure perfectly works! Now my posts can show Updated Date with the same format and html tags as that of Published Date.

    Thank you so much!

    There’s still one more thing I want to ask, I found that the Published Date is not removed but is just ‘hided’ with CSS, will Google still using Published Date as the date of my posts shown on their search result pages?

    Thanks!

    • This reply was modified 3 months ago by  philip2041.
    philip2041

    (@philip2041)

    Hi @gejay ,

    I found something useful about how search engine determines date of post:
    https://webmasters.stackexchange.com/questions/18395/how-does-google-recognize-publish-date-of-a-post
    https://webmasters.googleblog.com/2019/03/help-google-search-know-best-date-for.html

    According to Google webmaster blog, Google determines the date of a post using a variety of factors.

    It seems that the html tags is not a important sign it will use to determine a post’s date, because I found that the updated date of posts on Lifewire.com is just written in regular <div> tag, the updated date can still be shown on Google search result pages.

    In my opinion, Google may looks for the text of date that is shown next to the post title and uses it as the date shown on search result page.

    I don’t know whether your CSS method will work to make the updated date show on search result page, I will try it first and wait to see the result.

    If it doesn’t work, I think the published date should be removed in the code, or place it behind the updated date.

    Thanks!

    Theme Author Styled Themes

    (@gejay)

    Hello @philip2041,

    All hidden text is not considered misleading.
    For instance; Reference for hidden texts and links

    Please see the result and let us know.

    Note: We don’t recommend you to modify the parent theme unless you’re performing any updates.

    Thanks!

    philip2041

    (@philip2041)

    Hi @gejay ,

    I didn’t mean misleading.

    As mentioned in the content in the link you posted above, search engine can see the hidden text, so the published date that is hidden with CSS still can be seen by Google, hence its search result page may still display the initial published date for my posts.

    However, I will wait a few days and see the result and let you know if it works.

    Thanks!

    Hi @gejay,

    After I used your method, I waited for about two weeks, only found Google still displays publish date, not update date.

    Then I edited template-tags.php to put the code of Update Date in front of Publish Date, as in that way the Update Date will be the first date seen by search engines, so I thought that will work, but the date shown on Google was still publish date after I waited for another week.

    Then I checked the source code of my web page, and found that a plugin called Yoast SEO adds publish date to the head section in a meta tag, I think it might be that plugin affecting the decision of search engine about the date of post, so I disabled the plugin, and waited for another few days. But still nothing changes on the date shown on search engine.

    At last, I removed the code of publish date in template tags.php, and this time, search engine stopped showing Publish Date of my post, and after a few days it started showing Update Date for my posts.

    So my problem is solved, thanks for all your helps!

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