0

I have been trying this for hours and just not getting it, any help would be highly appreciated. I am creating a code in template tags to show the last modified date on my WordPress website, so far it looked like this: http://prntscr.com/nn2kvv

What I actually want to do is, whenever I update the post it should conditionally replace the published to Last Updated. This is my code so far:

if ( ! function_exists( 'chicken_wings_posted_on' ) ) :
/**
* Prints HTML with meta information for the current post-date/time.
*/
function chicken_wings_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>';

/**
* show last updated date
*/
$u_time = get_the_time('U');
$u_modified_time = get_the_modified_time('U');
if ($u_modified_time >= $u_time + 86400) {
echo '<p class = "last-updated-up">Last updated on ';
the_modified_time('F jS, Y');
echo "</p> "; }
}

There is a class "updated", it is somehow hidden, and I tried changing the class to my CSS styles, while removing the code to show the last update, like this:

if ( ! function_exists( 'chicken_wings_posted_on' ) ) :
/**
* Prints HTML with meta information for the current post-date/time.
*/
function chicken_wings_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="last-updated-up" datetime="%3$s">%4$s</time>';
}

I got this result: http://prntscr.com/nn2nrf

I want the output to be Last Updated when the post is modified, I am missing some conditions, please help Thanks!!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.