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

如何从Yoast Breadcrumbs中移除xmlns:v="http://rdf.data-vocabulary.org/#"属性?

移除Yoast Breadcrumbs中xmlns:v属性的两种最优方案

两种方案都不需要完全重写面包屑逻辑,也不用修改Yoast插件核心文件,可避免插件更新后修改丢失。

方案1:使用Yoast原生过滤器(全局生效,推荐)

将以下代码添加到你当前使用主题的functions.php文件中,即可全局处理所有Yoast面包屑的输出内容:

add_filter( 'wpseo_breadcrumb_output', 'remove_rdf_namespace_from_breadcrumbs' );
function remove_rdf_namespace_from_breadcrumbs( $output ) {
    // 移除指定的xmlns:v属性
    $output = str_replace( 'xmlns:v="http://rdf.data-vocabulary.org/#"', '', $output );
    // 若需同时移除所有v:前缀的RDF属性,可取消注释下行代码
    // $output = preg_replace( '/\s*(typeof|rel|property)="v:[^"]+"/', '', $output );
    return $output;
}

该方案无需修改你原有调用面包屑的代码,适配性最高,维护成本最低。

方案2:修改调用代码(仅当前位置生效)

如果你只需要在当前调用面包屑的位置移除该属性,不需要全局生效,可以直接修改你原本的调用代码,将面包屑内容先获取为字符串再做处理后输出:

<?php
if ( function_exists('yoast_breadcrumb') ) {
    // 第三个参数设为false,获取面包屑内容字符串而不直接输出
    $breadcrumb = yoast_breadcrumb('<span id="breadcrumbs">','<span class="print-holder"><a href="javascript:window.print()" aria-label="Print"><i class="fa fa-print print-icon" aria-hidden="true"></i></a></span></span>', false );
    // 移除目标属性后输出
    echo str_replace( 'xmlns:v="http://rdf.data-vocabulary.org/#"', '', $breadcrumb );
}
?>

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.01 07:54:02