方法1:
效果:
打开functions.php,加入:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
//添加老文章提示信息 function old_content_message($content) { $modified = get_the_modified_time('U'); $current = current_time('timestamp'); $diffTime = ($current - $modified) / (60 * 60 * 24); global $wp; $current_url = home_url(add_query_arg(array(),$wp->request)); if ($diffTime > 365 and !strstr($current_url, "feel") ) { $content = $content.'<div class="warn">本文最后更新于'.get_the_modified_time('Y年n月j日'). ',已超过 1 年没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!</div>'; } return $content; } add_filter('the_content', 'old_content_message'); |
CSS效果:
|
1 |
.old-message{padding:10px;color: #DB7C22;font-size: 14px;background: #FFFCEF;border: solid 1px #FFBB76;border-radius: 2px;box-shadow: 0 0 3px #ddd;} |
方法2(推荐):
functions.php:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
//添加老文章提示信息 function old_content_message($content) { $modified = get_the_modified_time('U'); $current = current_time('timestamp'); $diffTime = ($current - $modified) / (60 * 60 * 24); global $wp; $current_url = home_url(add_query_arg(array(),$wp->request)); if ($diffTime > 365 and !strstr($current_url, "feel") ) { $content = $content.'<div class="warn">本文最后更新于'.get_the_modified_time('Y年n月j日'). ',已超过 1 年没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!</div>'; } return $content; } add_filter('the_content', 'old_content_message'); |
如果想出现在文章开头,则改为:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
//添加老文章提示信息 function old_content_message($content) { $modified = get_the_modified_time('U'); $current = current_time('timestamp'); $diffTime = ($current - $modified) / (60 * 60 * 24); global $wp; $current_url = home_url(add_query_arg(array(),$wp->request)); if ($diffTime > 365 and !strstr($current_url, "feel") ) { $content = '<div class="warn">本文最后更新于'.get_the_modified_time('Y年n月j日'). ',已超过 1 年没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!</div>'.$content; } return $content; } add_filter('the_content', 'old_content_message'); |
CSS:
|
1 2 3 4 5 6 7 8 9 10 |
/* 提醒 */ .warn { color: #ad9948; background: #fff4b9 url(img/warn.png) -1px -1px no-repeat; border: 1px solid #eac946; overflow: hidden; margin: 10px 0; padding: 15px 15px 15px 35px; font-size: 14px; } |






最新评论
站长您好,亚马逊云咨询推广资源,望建立联系,可邮件,谢谢。
换友情链接吗?
看你的站做的挺不错的
恭喜!!太强了,硕博连读啊
雁过留毛,人过留名。
看不懂但大受震撼
每天都在战争,希望2026和平.
ZeroTier 看过多篇帖子,目前群辉、飞牛os、win11 、安卓、ubuntu ≥18.04 顺利通过,这篇相对于简单 实用、特来感谢 🙄