WordPress 技巧:解决 rel="category tag" 问题以便通过 W3C 验证

当你使用 W3C 验证服务去检查一个 WordPress 页面的时候,会发生:“Bad value category tag for attribute rel on element a:” 的错误,这是因为 WordPress 会在分类的链接上添加 rel="category tag" 的属性,而目前这两个属性还没有得到 W3C 的 HTML5 验证器的认可,所以会报错。其实在目前 HTML5 规范还没有完全确定的情况下,这个错误其实并不是很大的问题。但是如果你感觉不爽,一定要让自己的页面通过 W3C 的验证,你可以在你当前主题的 functions.php 文件添加如下的代码:

add_filter( 'the_category', 'wpjam_fix_catgory_rel' );

function wpjam_fix_catgory_rel ( $text ) {
	$text = str_replace('rel="category tag"', "", $text); return $text;
}

©我爱水煮鱼,本站推荐使用的主机:阿里云,国外主机建议使用BlueHost

本站长期承接 WordPress 优化建站业务,请联系微信:「chenduopapa」。