B2主题 SEO 优化实战:TDK 设置与结构化数据

背景

内容站的 SEO 至关重要。本文在 B2 子主题中实现标题/描述/关键词自定义,并输出 Schema 结构化数据。

一、TDK 输出

Text
add_action('wp_head', function () {
    if (is_single()) {
        $d = get_post_meta(get_the_ID(), 'ji_seo_desc', true);
        echo '';
    }
}, 5);

二、规范地址与分页

Text
add_action('wp_head', function () {
    if (is_singular()) {
        echo '';
    }
});

三、Article 结构化数据

Text
add_action('wp_head', function () {
    if (!is_single()) return;
    $json = array(
        '@context' => 'https://schema.org',
        '@type' => 'Article',
        'headline' => get_the_title(),
        'datePublished' => get_the_date('c'),
        'author' => array('@type' => 'Person', 'name' => get_the_author()),
    );
    echo '' . json_encode($json, JSON_UNESCAPED_UNICODE) . '';
});

注意事项

  • TDK 建议提供后台自定义字段,避免手动改代码。
  • 结构化数据必须与实际页面内容一致,避免搜索引擎处罚。

给TA打赏
共{{data.count}}人
人已打赏
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
签到成功