如上图,参考微信公众号文章,在文章底部自动添加文章最新修改时间。
我比较讨厌网站后台装一大堆的插件,今天分享的是不使用插件如何实现这个功能。
首先,我们打开主题的function.php文件,插入进去如下代码即可:
/**
* @desc 文章最后更新时间/全局
* @param $content
* @return string
*/
function my_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-j h:s a' );
$custom_content .= '<p class="last-updated entry-meta">最后更新 ' . $updated_date . '</p>';
}
$custom_content .= $content;
return $custom_content;
}
add_filter( 'the_content', 'my_last_updated_date' );
© 版权声明
文章版权归作者所有,未经允许请勿转载。
相关文章
暂无评论...