0

I would like to show published time "Posted 4:15pm" for the first 24 hours, after 24hours show full published date and time "September 27, 2016 at 4:15pm"

Any suggestions? Thanks in advance

1

This should do it.

// See if the post is older than 24 hours.
if ( get_post_time() <= strtotime( '-1 day' ) ) {
  echo 'Published more than 24 hours ago.';
} else {
  echo 'Published within the last 24 hours.';
}
  • @choche if my answer solved your question, please accept it. :-) – cowgill Oct 1 '16 at 4:52
0

So far :

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

$time_posted = esc_html( get_the_time() );
$u_time = get_the_time('U'); 
$u_modified_time = get_the_modified_time('U');

$posted_on = sprintf(
    _x( '%s', 'post date', 'ci' ),
    '' . $time_string . ''
);

if ($u_modified_time >= $u_time + 86400) :
   the_modified_time('g:i a'); 
else :
   echo ' . $posted_on . ' at ' . $time_posted . ';

This is working but using modified date, i want if published date is less than 24 hours show time and after 24 hours show date and time

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.