You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在WordPress中为自定义post_tag页面添加noindex?

实现自定义标签页面批量设置Noindex的代码

直接在主题的functions.php文件中添加以下代码,即可为所有post_tag开头的标签页面设置noindex:

function custom_post_tag_noindex() {
    // 判断当前是否为自定义标签(post_tag)归档页
    if ( is_tax( 'post_tag' ) ) {
        // 输出noindex元标签
        echo '<meta name="robots" content="noindex, follow">';
    }
}
// 挂载到wp_head钩子,确保标签输出在页面头部
add_action( 'wp_head', 'custom_post_tag_noindex' );

代码说明

  • is_tax( 'post_tag' ):精准匹配你的自定义标签分类法页面,对应abc.com/post_tag/item的URL结构
  • wp_head钩子:保证元标签输出在HTML头部的正确位置,符合搜索引擎抓取规范
  • noindex, follow:让搜索引擎不索引该标签页,但允许跟随页面内的链接;若需要完全禁止抓取可改为noindex, nofollow

注意事项

  • 修改functions.php前请备份文件,避免代码错误导致网站异常
  • 该代码与Yoast、Rank Math插件兼容,会直接输出元标签,优先级高于插件无对应设置时的默认输出

内容的提问来源于stack exchange,提问作者John

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 00:54:29