# WordPress主题RiPro如何显示文章最后更新时间

*Published:* 2023-12-01
*Author:* 客服001

#### 温馨提醒

如果文章内容或图片资源失效，请留言反馈，我们会及时处理，谢谢

本文最后更新于2023年12月1日，已超过 180天没有更新



样式一
---

1、在WordPress主题中 functions.php 文件中添加以下代码：

```
//文章显示最后更新时间 
function dujin_post_update( $content ) {
$u_time = get_the_time('U'); 
$u_modified_time = get_the_modified_time('U'); 
$custom_content = ''; 
if ($u_modified_time >= $u_time + 86400) {
$updated_date = get_the_modified_time('Y-m-d日'); //这里设置时间显示格式，可自由调整。
$custom_content .= '<p class="dujin-update">本文最后更新于<code>'. $updated_date . '</code>，因文章时效性，若有错误或相关图文已失效，请在下方留言或联系<a href="http://wpa.qq.com/msgrd?v=3&uin=3387285338&site=qq&menu=yes"><b>发稿者</b></a>。</p>';  
} 
    $custom_content .= $content;
    return $custom_content;
}
add_filter( 'the_content', 'dujin_post_update' );
```

其中86400就是秒数，意思是超过24小时才显示最后更新时间，这个时间可以根据自己的需求去制定。到这里，文章最近的编辑时间就能自动添加了。

2、添加CSS文件

如果想要实现本文章顶部展现颜色和边框的效果，还需要设置下CSS，代码如下：

```
//文章显示最后更新时间 
.dujin-update{padding:10px 20px;background-color:#FEEFB3;border-radius:6px;border:1px solid;font-size:14px;text-align:left}
```

想要这个代码生效，理论上可以直接添加到主题的CSS样式文件中，或者单独建一个CSS文件到网站。

样式二
---

1、 functions.php 文件中添加以下代码：

```
//文章显示最后更新时间
function wpb_last_updated_date( $content ) {
$u_time = get_the_time('U'); 
$u_modified_time = get_the_modified_time('U'); 
$custom_content = ''; 
if ($u_modified_time >= $u_time + 86400) { 
$updated_date = get_the_modified_time('Y.m.d');
$updated_time = get_the_modified_time('h:i  因文章时效性，若有错误或相关图文已失效，请在下方留言。'); 
$custom_content .= '<p class="last-updated">本文最后更新于 '. $updated_date . '  '. $updated_time .'</p>';  
} 
 
    $custom_content .= $content;
    return $custom_content;
}
add_filter( 'the_content', 'wpb_last_updated_date' );
```

2、添加CSS文件

```
/* 文章显示最后更新时间开始
.last-updated {
    color: #db7c22;
background: #fff4b9;
border: 1px solid #eac946;
overflow: hidden;
margin: 10px 0;
padding: 15px 15px 15px 35px;
font-size: 14px;
}
```