Set navigation menu inside WordPress Appearance > Menus

Web Developers Corner

Make WordPress validate for HTML5 by getting rid of rel=”category tag”

worpress-rel-cat

Have you tried validating your WordPress site using the W3C validator thinking your site was up to par with today’s standards? Only to see a long list of errors on your site?

Don’t worry, we all have been there, well most of us at least. And there is only one thing to do about the problems, fix them. If your site is using html5, then you probably have a lot of errors complaining about a bad value for your rel attributes (rel=”category tag”)

If this is the error you are searching for then you can relax because there is an easy solution for this problem.

  • error Make Wordpress validate for HTML5 by getting rid of rel=category tagLine 562, Column 288: 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.
    …press" title="View all posts in WordPress" rel="category tag">WordPress</a></p>

    Syntax of link type valid for <a> and <area>:
    A whitespace-separated list of link types listed as allowed on <a> and <area> in the HTML specification or listed as an allowed on <a> and <area> on the Microformats wiki without duplicate keywords in the list. You can register link types on the Microformats wiki yourself.
    Syntax of absolute IRI:
    An absolute URL. For example: http://example.org/hello, but not /hello. Spaces should be escaped as %20.

The problem is not within your theme but in fact inside the core of WordPress, more specifically the function the_category() And to fix this all you need to do is add a few lines of code to your themes functions.php file

add_filter('the_category', 'fix_cat');

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

What we have done here is adding a filter to the the_category function. This filters the contents from the function through a function I have chose to call fix_cat(). On the next lines we can see what the function does. I takes 1 argument $text and returns it after we have replaced all occurenses of rel=”category tag” with a blank string (“”)

Tagged , , , , ,

Share this post

PinIt

About Fredrik Hugås

Fredrik Hugås is a 28-year-old web designer from Norway, more comming ;)

View all posts by Fredrik Hugås →

One thought on “Make WordPress validate for HTML5 by getting rid of rel=”category tag”

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>