Last Modified/Updated Date on the post

Posted in: Newsmag
Post count: 48

Hi, I am looking to display “last modified date” on the posts that are updated after the published date. When i put the following code in function.php, the newsmag theme gives error and doesn’t display anything. Could you help me as to where i should put the code to do the mentioned task.

function wpb_last_updated_date( $content ) {
$u_time = get_the_time(‘U’);
$u_modified_time = get_the_modified_time(‘U’);
if ($u_modified_time >= $u_time + 86400) {
$updated_date = get_the_modified_time(‘F jS, Y’);
$updated_time = get_the_modified_time(‘h:i a’);
$custom_content .= ‘<p class=”last-updated”>Last updated on ‘. $updated_date . ‘ at ‘. $updated_time .'</p>’;
}

$custom_content .= $content;
return $custom_content;
}
add_filter( ‘the_content’, ‘wpb_last_updated_date’ );

Post count: 23312

Hi,

Please check the following topic here -> https://forum.tagdiv.com/topic/how-to-make-this/ and try to implement the last modified date as my explanation.
After each change, you should clear all your caches, purge all CDN files if you are using the CDN system and check the results.

Thanks for your understanding!

Post count: 48

Hi thank you but that process only changes the date to “Modified on date” whereas I need the function which could only change the date of posts which are updated later after their publish date and not every post.
e.g if a post has been updated;
if the current date is > publish date then
update the date to current date and change ‘publish on’ to ‘updated on’ current date;
The above-mentioned function also does a similar thing but it doesn’t work on Newsmag theme.

Plz suggest solution.

Post count: 23312

Hi m0re,

Sorry for this inconvenience, but please notice that our theme does not have any such an option that allows you to achieve this, sorry! This changes could be made only via custom work and please notice that we cannot provide any support in this regard, sorry! If you are not aware of the steps which are needed to take in this case, please consider hiring a freelancer/developer to help you because we cannot provide custom services at the moment, sorry!

Thanks for your understanding!

Post count: 48

Hi, a user on this forum (Pedroarmindo1) helped me fix the basic problem. I figured out that Single_template_xx.php should be edited

We need to find this code in the file
<?php echo $td_mod_single->get_date(false);?>

and replace it with the following code

<?php echo the_date(false, ‘<span class=”td-post-date”>Publicado em: ‘,'</span>’); ?>
</div>
<div class=”info-line”>
<?php echo the_modified_date(false, ‘<span class=”td-post-date td-post-modified-date”>Atualizado em: ‘,'</span>’); ?>

But there is 1 more issue; if anyone could help here;
1 – Two dates are displaying in two lines. See here http://prntscr.com/gk9wd9
There should be only single date “Updated on: September 12, 2017” instead of
also displaying the ‘publish date’ and ‘updated date’

2 – Also how the date could be formatted. What CSS should be used.

Post count: 94

Hi
I used the following code into the loop-single.php of my child theme and it works fine

<?php $u_time = get_the_time(‘U’);
$u_modified_time = get_the_modified_time(‘U’);
if ($u_modified_time >= $u_time + 86400) {?>
– ultima modifica:
<?php the_modified_time(‘j F Y’); }?>

Post count: 94

and it adds the modified date to the string in which you usually see the date

Post count: 48

That means it only shows ‘updated on (date)’ only when a post is updated otherwise it will show only publish date normally?

Post count: 48

I have activated Style 3 for the post in my Newsmag. Will this code still work in loop-single.php? or i should use it in someother file. If it has to be put in loop-single.php, where exactly should i put it?

Post count: 94

the updated date appears in the same line where you can see the author and the normal date

if the post were updated in a day different from the day of first publication the new date is added (so you’ll se published on XXX and update on YYY) otherwise (if you modify the post in the same day) you’ll see just the first date

hope it can help

Post count: 48

Thanks Paologalli, I am using Style 3 and using single_template_3.php for this. You just suggested me to put the code in loop-single.php. Should i still put the code in loop-single.php or single_template_3.php? and by the way, where should i put the code in the file, can you share the screenshot plz?

Post count: 19

Hi More,

Not sure if you found out the solution yet, but if you haven’t then I’ve implemented the how to display last modified time instead of published time on my blog http://www.techbuzz.in and also I’ve blogged about the same.

However, the effect of this has to be studied when NewsPaper theme is updated.

I’ve written about the benefits and problems with implementing ‘last_modified_time’.

http://www.techbuzz.in/tagdiv-newspaper-theme-last-updated-modified-time.php

Bloggers should use use this feature cautiously as mis-using it might attract penalty from Google.

Hope this helps.

Viewing 12 posts - 1 through 12 (of 12 total)
The forum ‘Newsmag’ is closed to new topics and replies.