WordPress生成无效标记,如何删除它? [英] WordPress generating invalid markup, How to remove it?
问题描述
您好我正在尝试使用以下代码获取与其中的帖子关联的类别:
Hi I am trying to get the categories associated with a post in it's meta section by using the following code:
<div>FILED AS: <span class="gf-post-meta-result"><?php the_category(' • ') ?></span></div>
WordPress生成的标记为:
<div>FILED AS: <span class="gf-post-meta-result"><a href="http://localhost/test/category/uncategorized/" title="View all posts in Uncategorized" rel="category tag">Uncategorized</a></span></div>
问题:
由wordpress生成的这部分 rel =category tag
使我的代码无效。 W3c Validator抛出错误说:
This part rel="category tag"
generated by wordpress is making my code invalid. W3c Validator throws an error saying:
元素a的属性rel的错误值类别标记:字符串类别不是注册关键字或绝对URL 。路径组件中的空格。使用%20代替空格。
Bad value category tag for attribute rel on element a: The string category is not a registered keyword or absolute URL. Whitespace in path component. Use %20 in place of spaces.
…w all posts in Uncategorized" rel="category tag">Uncategorized</a></span></div>
知道如何纠正这个问题吗?
推荐答案
只需将以下代码粘贴到 functions.php
主题文件夹中的文件
Just paste the following code in your functions.php
file inside your theme folder
function remove_category_rel($output)
{
$output = str_replace(' rel="category tag"', '', $output);
return $output;
}
add_filter('the_category', 'remove_category_rel');
这篇关于WordPress生成无效标记,如何删除它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!