WordPress generating invalid markup, How to remove it?

时间秒杀一切 提交于 2019-12-10 17:06:39

问题


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(' &bull; ') ?></span></div>

WordPress is generating the markup as:

<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>

The issue:

This part rel="category tag" generated by wordpress is making my code invalid. W3c Validator throws an error saying:

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>

Any idea how to rectify this?


回答1:


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');



回答2:


These two rel values are not invalid. The validator is not up to date.

  • tag is defined in the HTML5 spec.
  • category is registered officially.

So it's no problem to use these values. The validator will probably catch up in the future.



来源:https://stackoverflow.com/questions/14114465/wordpress-generating-invalid-markup-how-to-remove-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!