The post_date_column_time WordPress PHP filter allows you to modify the published time of the post in the admin post list.
Usage
add_filter('post_date_column_time', 'my_custom_published_time', 10, 4); function my_custom_published_time($t_time, $post, $column_name, $mode) { // your custom code here return $t_time; }
Parameters
- $t_time (string) – The published time.
- $post (WP_Post) – Post object.
- $column_name (string) – The column name.
- $mode (string) – The list display mode (‘excerpt’ or ‘list’).
More information
See WordPress Developer Resources: post_date_column_time
Examples
Change the date format of the published time
Change the date format of the published time to a custom format.
add_filter('post_date_column_time', 'custom_published_time_format', 10, 4); function custom_published_time_format($t_time, $post, $column_name, $mode) { return get_the_time('F j, Y g:i a', $post); }
Add a custom prefix to the published time
Add a custom prefix like “Published at” to the published time.
add_filter('post_date_column_time', 'add_prefix_to_published_time', 10, 4); function add_prefix_to_published_time($t_time, $post, $column_name, $mode) { return 'Published at ' . $t_time; }
Show time ago instead of the published time
Display the time ago, like “2 hours ago”, instead of the published time.
add_filter('post_date_column_time', 'show_time_ago', 10, 4); function show_time_ago($t_time, $post, $column_name, $mode) { return human_time_diff(get_post_time('U', true, $post), current_time('timestamp')) . ' ago'; }
Display published time only for a specific column
Modify the published time only for a specific custom column.
add_filter('post_date_column_time', 'modify_published_time_for_specific_column', 10, 4); function modify_published_time_for_specific_column($t_time, $post, $column_name, $mode) { if ($column_name == 'my_custom_column') { return 'Custom: ' . $t_time; } return $t_time; }
Hide the published time for draft posts
Hide the published time for draft posts in the admin post list.
add_filter('post_date_column_time', 'hide_published_time_for_drafts', 10, 4); function hide_published_time_for_drafts($t_time, $post, $column_name, $mode) { if ($post->post_status == 'draft') { return '—'; } return $t_time; }