WordPress显示文章最后一次更新时间

本文最后更新于2022.04.08-14:38,某些文章具有时效性,若有错误或已失效,请在下方留言或联系涛哥

展示效果

代码

将下面代码放入主题functions.php中

//给 WordPress 站点的文章页面添加最后一次更新时间
function 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-H:s'); //这里设置时间显示格式,可自由调整。
$custom_content .= '<p class="update">本文最后更新于<code>'. $updated_date . '</code>,某些文章具有时效性,若有错误或已失效,请在下方留言或联系<a href="https://liutao.sale/contact"><b>涛哥</b></a>。</p>';  
} 
    $custom_content .= $content;
    return $custom_content;
}
add_filter( 'the_content', 'post_update' );

通过css控制样式

.update{
padding:10px 20px;
background-color:#0f1214;
border-radius:6px;
border:1px solid;
font-size:14px;
text-align:left;
}

 

上一篇 Java io实现系统注册登录
下一篇 Java-第一课
距离活动开始
--
:
--
:
--
:
--
00 : 00 : 00
2026430星期四

今日时光

00 : 00 :00
已过 0 剩余 0
0%
目录
涛哥

涛哥管理员

一名95后Java全栈开发程序员,95后技术分享博主,致力于技术分享和个人项目创作

本月创作热力图