Php 在WordPress中获取修改后的时间:X分钟/天/年前
这是我的代码:Php 在WordPress中获取修改后的时间:X分钟/天/年前,php,wordpress,last-modified,Php,Wordpress,Last Modified,这是我的代码: add_filter('the_modified_time', 'dy'); function dy() { $time = get_the_modified_time(); $mytimestamp = sprintf(__('%s ago'), human_time_diff($time)); return $mytimestamp; } 它不能像我希望的那样工作。我做错了什么 非常感谢您的帮助。您的过滤器只会影响功能。可能是您的主题使用不同的时间函数显
add_filter('the_modified_time', 'dy');
function dy() {
$time = get_the_modified_time();
$mytimestamp = sprintf(__('%s ago'), human_time_diff($time));
return $mytimestamp;
}
它不能像我希望的那样工作。我做错了什么
非常感谢您的帮助。您的过滤器只会影响功能。可能是您的主题使用不同的时间函数显示帖子时间。尝试使用以下命令
add_filter('get_the_modified_time', 'dy');
add_filter('get_the_modified_date', 'dy');
add_filter('get_the_date', 'dy');
add_filter('the_date', 'dy');
add_filter('get_the_time', 'dy');
add_filter('the_time', 'dy');
function dy() {
$time = strtotime(get_post()->post_date);
$time_ago = human_time_diff($time, current_time('timestamp'));
return sprintf(__('%s ago'), $time_ago);
}
也许这个插件可以做到这一点: