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;
}

 

版权声明:
作者:涛哥
链接:https://ltbk.net/bulid/wp/article/491.html
来源:涛哥博客
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
打赏
海报
WordPress显示文章最后一次更新时间
本文最后更新于2022.04.08-14:38,某些文章具有时效性,若有错误或已失效,请在下方留言或联系涛哥。展示效果 代码 将下面代码放入主题functions.php中 //给 ……
<<上一篇
下一篇>>
文章目录
关闭
目 录