M
M
msdoc112021-09-30 20:56:16
WordPress
msdoc11, 2021-09-30 20:56:16

How to add post time to wordpress function?

There is a code:

add_filter('the_time', 'dynamictime'); function dynamictime() {
    global $post;
    $date = $post->post_date;
    $time = get_post_time('G', true, $post);
    $mytime = time() - $time; 
    if($mytime > 0 && $mytime < 1*24*60*60) $mytimestamp = sprintf(__('%s ago'), human_time_diff($time));
    else $mytimestamp = date(get_option('date_format'), strtotime($date)); return $mytimestamp;
    }

Displays the publication date, such as "10 seconds ago" or "an hour ago", and after a day since publication, displays the normal date. How to add to this also the exact time after the day, like this: "9.9.2021 14:00". Now it's just "9/9/2021".

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Karabanov, 2021-10-01
@msdoc11

date_formatand time_formatare set in the admin panel in the settings section.

$date_format = get_option('date_format');
$time_format = get_option('time_format');
$mytimestamp  = date("{$date_format} {$time_format}", strtotime($date));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question