在WordPress中显示帖子的上次更新日期

在WordPress中显示帖子的上次更新日期,wordpress,Wordpress,我想在WordPress中显示帖子的最后更新日期,我可以找到这段代码,我必须把它放在function.php中 function wpb_last_updated_date( $content ) { $u_time = get_the_time('U'); $u_modified_time = get_the_modified_time('U'); if ($u_modified_time >= $u_time + 86400) { $updated_date = get_the_

我想在WordPress中显示帖子的最后更新日期,我可以找到这段代码,我必须把它放在function.php中

function wpb_last_updated_date( $content ) {
$u_time = get_the_time('U'); 
$u_modified_time = get_the_modified_time('U'); 
if ($u_modified_time >= $u_time + 86400) { 
$updated_date = get_the_modified_time('F jS, Y');
$updated_time = get_the_modified_time('h:i a'); 
$custom_content .= '<p class="last-updated">Last updated on '. $updated_date . ' at '. $updated_time .'</p>';  
} 

$custom_content .= $content;
return $custom_content;
}
add_filter( 'the_content', 'wpb_last_updated_date' );
函数wpb\u上次更新日期($content){
$u_time=获取时间('u');
$u_modified_time=获取_modified_time('u');
如果($u_-modified_-time>=$u-time+86400){
$updated_date=获取修改后的时间('fjs,Y');
$updated_time=get_the_modified_time('h:ia');
$custom\u content.='

上次更新日期:'$updated\u date.'在'$updated\u time.'

'; } $custom_content.=$content; 返回$custom_内容; } 添加过滤器(“内容”、“wpb上次更新日期”);
它的工作,但问题是,我也有更新日期显示在网页上,公文包

如何限制博客帖子上显示的更新日期


感谢您的帮助。

只需添加一个条件来检查帖子类型:

function wpb_last_updated_date( $content ) {
    $u_time = get_the_time('U'); 
    $u_modified_time = get_the_modified_time('U'); 
        if ($u_modified_time >= $u_time + 86400 && is_singular('post')) { 
            $updated_date = get_the_modified_time('F jS, Y');
            $updated_time = get_the_modified_time('h:i a'); 
            $custom_content .= '<p class="last-updated">Last updated on '. $updated_date . ' at '. $updated_time .'</p>';  
        } 

    $custom_content .= $content;
    return $custom_content;
    }
add_filter( 'the_content', 'wpb_last_updated_date' );
函数wpb\u上次更新日期($content){
$u_time=获取时间('u');
$u_modified_time=获取_modified_time('u');
如果($u_-modified_-time>=$u-time+86400&&是单数('post')){
$updated_date=获取修改后的时间('fjs,Y');
$updated_time=get_the_modified_time('h:ia');
$custom\u content.='

上次更新日期:'$updated\u date.'在'$updated\u time.'

'; } $custom_content.=$content; 返回$custom_内容; } 添加过滤器(“内容”、“wpb上次更新日期”);

查询单个帖子并将帖子类型作为参数。

这与php8.0兼容吗?我收到一条错误消息:警告:第108行/var/www/html/wordpress/wp content/themes/child theme/functions.php中未定义变量$custom\u content='