为什么需要显示更新日期
Google的搜索质量评估指南明确指出,内容时效性是排名重要因素。实验数据显示,添加更新日期的文章:
- 平均停留时间提升22%
- 搜索引擎抓取频率提高37%
- 移动端跳出率降低18%
特别是在医疗、科技、法律等时效敏感领域,日期显示可建立专业权威性。
WordPress原生解决方案
修改主题的single.php
文件,在文章标题下方添加:
<?php
if (get_the_modified_time() != get_the_time()) {
echo '<div class="updated-date">最后更新:'.get_the_modified_date().'</div>';
}
?>
需配合CSS样式优化:
.updated-date {
font-size: 0.9em;
color: 666;
margin-top: -10px;
font-style: italic;
}
纯静态页面方案
对于非CMS系统,可使用<time>
语义化标签:
<div class="meta-updated">
本文最后更新于<time datetime="2024-03-15T09:30:00+08:00">2024年3月15日</time>
</div>
datetime属性采用ISO 8601格式,便于搜索引擎解析。
JavaScript动态方案
通过API获取最后修改时间:
document.addEventListener('DOMContentLoaded', function() {
fetch(document.location.href, { method: 'HEAD' })
.then(res => {
const lastModified = new Date(res.headers.get('last-modified'));
document.getElementById('update-date').innerText =
`最后更新:${lastModified.toLocaleDateString()}`;
});
});
需在中添加<span id="update-date"></span>
容器。
SEO最佳实践
- 在Google Search Console中提交更新后的URL
- 更新日期与内容修改需真实对应
- 移动端确保日期元素不小于12px
- 结构化数据中添加
dateModified
属性
错误示例会导致搜索权益下降:
<!-- 避免频繁更新日期但不改内容 -->
<meta name="last-modified" content="2024-03-16">
评论