The get_comment_date WordPress PHP filter allows you to modify the displayed date of a comment on your WordPress site.
Usage
add_filter('get_comment_date', 'your_custom_function', 10, 3);
function your_custom_function($date, $format, $comment) {
// your custom code here
return $date;
}
Parameters
$date(string|int): The formatted date string or Unix timestamp.$format(string): The PHP date format.$comment(WP_Comment): The comment object.
More information
See WordPress Developer Resources: get_comment_date
Examples
Change the comment date format
Change the comment date format to display in a more friendly style.
add_filter('get_comment_date', 'change_comment_date_format', 10, 3);
function change_comment_date_format($date, $format, $comment) {
$new_format = 'F j, Y';
return date($new_format, strtotime($date));
}
Display time ago instead of date
Show the comment date as “time ago” (e.g., “2 days ago”).
add_filter('get_comment_date', 'display_time_ago', 10, 3);
function display_time_ago($date, $format, $comment) {
return human_time_diff(strtotime($date), current_time('timestamp')) . ' ago';
}
Add a custom prefix to comment date
Add a custom prefix to the displayed comment date, like “Posted on”.
add_filter('get_comment_date', 'add_custom_prefix', 10, 3);
function add_custom_prefix($date, $format, $comment) {
return 'Posted on ' . $date;
}
Display the comment date in uppercase
Change the displayed comment date to uppercase letters.
add_filter('get_comment_date', 'uppercase_comment_date', 10, 3);
function uppercase_comment_date($date, $format, $comment) {
return strtoupper($date);
}
Display comment date in a different language
Change the comment date to display in French.
add_filter('get_comment_date', 'comment_date_french', 10, 3);
function comment_date_french($date, $format, $comment) {
setlocale(LC_TIME, 'fr_FR.UTF-8');
return strftime('%A %d %B %Y', strtotime($date));
}
END