欢迎访问晨星博客!
语义化标签从来不是 SEO 的“加分项”,而是爬虫的“阅读眼镜”。Google 早已确认:语义化本身不直接参与排名算法,但它能显著降低搜索引擎理解页面结构的计算成本。对于内容站而言,这意味着新内容更快被索引、核心段落更精准地进入 Featured Snippet、面包屑与站点链接更稳定地展示。
WordPress 主题若仍在用 <div id="header"></div>、<div class="main-content"> 这种无语义容器堆砌布局,等于让爬虫在“盲盒”里猜内容边界。下面把内容页最关键的七个区块标签对应关系、结构化数据协作要点、无障碍落地细节一次讲透,文末附自查清单可直接拿去用。
WordPress 模板层级里,header.php、footer.php、sidebar.php 天然对应全局语义区块,别再用 <div class="site-header"> 兜底。
<header>(站点级):只放站标、全站搜索、主导航入口。文章页若把面包屑、发布时间、作者信息塞进这里,属于滥用——这些属于内容元数据,归 <article> 管。<nav>:专门给“主要导航系统”用。主菜单、分页导航、面包屑各自包一层 <nav aria-label="...">。侧边栏的“最新文章”“分类目录”属于辅助导航,建议用 <nav aria-label="侧边栏导航"> 区分层级,别让爬虫把次要入口当主干道抓。<main>:全页唯一,直接包裹核心内容区。WordPress 常见错误:index.php、archive.php、single.php 都把侧边栏塞进 <main> 里。正确做法是 <main> 只套 <article> 或文章列表循环,侧边栏放 <main> 之外、<aside> 里。<aside>:承载“与主内容关联度较低但可独立存在”的模块。侧边栏广告、相关推荐、作者卡片、标签云全归这里。注意:文章内部的“提示框”“引用卡片”若属于内容延伸,应用 <aside> 包在 <article> 内部,而非全局 <aside>。<footer>:版权声明、备案号、友情链接、社交图标。别把“回到顶部”按钮、JS 埋点代码当内容塞进去,它们不属于文档语义范畴。内容页的 <article> 是爬虫判定“独立可发布单元”的锚点。WordPress 单文章模板(single.php / singular.php)应确保:
<main id="primary">
<article itemscope itemtype="https://schema.org/BlogPosting" role="article">
<header class="entry-header">
<h1 class="entry-title" itemprop="headline">文章标题</h1>
<div class="entry-meta">
<time itemprop="datePublished" datetime="2024-05-20">2024-05-20</time>
<span itemprop="author" itemscope itemtype="https://schema.org/Person">
<span itemprop="name">作者名</span>
</span>
</div>
</header>
<div class="entry-content" itemprop="articleBody">
<!-- 正文段落、图片、视频 -->
<section aria-labelledby="heading-key-points">
<h2 id="heading-key-points">核心观点</h2>
<p>...</p>
</section>
<section aria-labelledby="heading-case-study">
<h2 id="heading-case-study">案例拆解</h2>
<figure>
<img src="..." alt="...">
<figcaption>图注说明</figcaption>
</figure>
</section>
</div>
<footer class="entry-footer">
<span class="tags" itemprop="keywords">标签A, 标签B</span>
<nav class="post-nav" aria-label="文章翻页">
<a rel="prev" href="...">上一篇</a>
<a rel="next" href="...">下一篇</a>
</nav>
</footer>
</article>
</main>
避坑指南:
<header> / <footer>:文章内部的元数据区块必须显式包裹,否则结构化数据 itemprop="headline"、datePublished 会“悬浮”在无父级上下文里,导致 Rich Results Test 报错。<section> 必须带标题:每个 <section> 里至少有一个 <h2>–<h6>,且建议用 aria-labelledby 指向该标题 ID。无标题的分组直接用 <div>,别强行语义化。<figure> 封装媒体:图表、代码块、视频、图片组合若有说明性标题,必须用 <figure> + <figcaption>。这能让爬虫把图片与周围文本建立强关联,提升图片搜索流量。| 维度 | 语义化 HTML(骨架) | 结构化数据 JSON-LD(标签) | 无障碍 ARIA / 原生属性(交互) |
|---|---|---|---|
| 核心作用 | 让机器“看懂”文档大纲 | 显式声明实体类型、属性、关系 | 让屏幕阅读器“可操作、可导航” |
| 典型协作 | <article itemscope itemtype="BlogPosting"> | 同一节点挂载 itemprop,或 <script type="application/ld+json"> 补全 | <nav aria-label="主导航">、<main role="main">(HTML5 已隐含) |
| 常见冲突 | 用 <div> 代替 <article> 导致 itemtype 无依附 | JSON-LD 写了 mainEntityOfPage 但 HTML 无 <main> / <article> 对应 | role="button" 加在 <a> 上破坏原生语义 |
| 检测工具 | W3C Validator / HTML5 Outliner | Google Rich Results Test / Schema Markup Validator | axe DevTools / NVDA 实测 |
实战原则:
<nav>、<main>、<time>、<address> 自带隐含 ARIA 角色,无需重复 role。itemprop="author" 对应 <span itemprop="name"> 可见文本)。aria-label 给无文本导航命名:面包屑、分页、侧边栏导航若无可见标题,必须加 aria-label,否则屏幕阅读器只会读“导航、导航、导航”。header.php 顶层用 <header role="banner">,内含 <nav aria-label="主导航">。single.php 核心区用 <main id="main" role="main"> 直接包裹 <article>,侧边栏在外。sidebar.php 根节点为 <aside role="complementary" aria-label="侧边栏">。footer.php 根节点为 <footer role="contentinfo">,无主导航重复。<article> 挂载 itemscope itemtype="https://schema.org/BlogPosting"(或 NewsArticle/TechArticle)。<h1 itemprop="headline">,不出现第二个 H1。<time itemprop="datePublished" datetime="YYYY-MM-DD"> + <time itemprop="dateModified">,datetime 格式 ISO 8601。<span itemprop="author" itemscope itemtype="https://schema.org/Person"><span itemprop="name">...</span></span>,并链接至作者存档页。itemprop="articleBody",内部不再嵌套其他 itemscope 实体。<section aria-labelledby="heading-xxx"> 包裹,id="heading-xxx" 落在 <h2> 上。<figure> + <figcaption>。<aside> 包在 <article> 内,aria-label="相关推荐"。<nav aria-label="面包屑"> + itemprop="breadcrumb" 列表结构。<head> 或 <body> 底部,实体 ID 与 HTML itemprop 指向一致。mainEntityOfPage 指向规范 URL,publisher 含 logo 对象(width≤600px, height≤60px)。image 字段使用文章首图/特色图绝对路径,尺寸≥1200px 宽。<nav>、<aside>、<section> 有 aria-label 或 aria-labelledby。<button aria-label="..."> 而非 <a href="#">。:focus-visible 可见不依赖鼠标 hover。aria-expanded="true",关闭时 false。把 <div class="header"> 改成 <header class="header"> 只是第一步。真正的语义化是内容建模:先问“这块内容在文档大纲里是什么角色”,再选标签。WordPress 主题开发时,建议把模板拆成 template-parts/header/site-header.php、template-parts/content/entry-header.php、template-parts/content/entry-meta.php 等细粒度部件,每个部件只负责一层语义,再由 single.php 组装。这样既利于子主题覆盖,也能让爬虫、屏幕阅读器、结构化数据验证工具在同一份 DOM 树上达成共识。
下次重构主题或接手旧站,把这份清单跑一遍,能省下不少“已收录不出词、富媒体不展示、无障碍审计不通过”的排查时间。
声明:原创文章请勿转载,如需转载请注明出处!