钩子文档

get_comment_date

💡 云策文档标注

概述

get_comment_date 是一个 WordPress 过滤器,用于修改返回的评论日期。它允许开发者自定义评论日期的显示格式或内容。

关键要点

  • 过滤器名称:get_comment_date
  • 参数:$comment_date(格式化日期字符串或 Unix 时间戳)、$format(PHP 日期格式)、$comment(WP_Comment 对象)
  • 源调用:apply_filters('get_comment_date', $comment_date, $format, $comment)
  • 相关函数:get_comment_date() 用于检索当前评论的日期
  • 引入版本:1.5.0

代码示例

function custom_comment_date( $date, $d, $comment ) {
    return mysql2date( 'F jS, Y', $comment->comment_date );
}
add_filter( 'get_comment_date', 'custom_comment_date', 10, 3);

注意事项

使用标准 PHP 日期格式字符,参考:http://php.net/manual/en/function.date.php


📄 原文内容

Filters the returned comment date.

Parameters

$comment_datestring|int
Formatted date string or Unix timestamp.
$formatstring
PHP date format.
$commentWP_Comment
The comment object.

Source

return apply_filters( 'get_comment_date', $comment_date, $format, $comment );

Changelog

Version Description
1.5.0 Introduced.

User Contributed Notes

  1. Skip to note 2 content

    An example of filtering the comment date format:

    function custom_comment_date( $date, $d, $comment ) {
    	return mysql2date( 'F jS, Y', $comment->comment_date );
    }
    add_filter( 'get_comment_date', 'custom_comment_date', 10, 3);

    Use the standard PHP date format characters: http://php.net/manual/en/function.date.php