Quick fix for rel=”category tag” in WordPress

Here is a quick tip for helping WordPress, WordPress 3.2 specifically, with the HTML5 spec. HTML5 spec says that only certain rel types are allowed and WordPress’ “category tag” isn’t one of them. Fortunately I found a good bit of code here http://smalldiary.com/wordpresshow-to-add-nofollow-to-category-links.html which strips out the current rel=”category tag” and adds a rel=”nofollow” as a filter in the fuctions.php file for the theme. By adding it to the functions.php for the theme this provides a theme wide fix rather than having to edit individual templates.

I altered the code a bit for my uses, however, as I’d still like the search engines crawling around my site so I stripped the code down to:
add_filter( 'the_category', 'add_nofollow_cat' );  function add_nofollow_cat( $text ) { $text = str_replace('rel="category tag"', "", $text); return $text; }
Now the W3 Validator has one less WordPress quirk to pickup on.

24 responses to “Quick fix for rel=”category tag” in WordPress”

  1. Bhushan Avatar
    Bhushan

    My function.php code like that…<?php

    /*

    * Loading DEVN's framework and HUBs library

    * (c) http://www.devn.co

    *

    */

    #Load main class

    require_once( get_template_directory().'/cgi/bin.php' );

    #Load registration for WP

    $devn = new devn();

    #

    #

    # END of REGISTRATION

    #

    #

    And where i keep this code..please assist mi…

  2. […] 29 of them were all from a WordPress-specific issue, which I fixed by following the instructions on this blog post. If you run the W3C Validation right now for http://www.jrconway.net, you’ll see that it […]

  3. […] Update 12:37: Fehler korrigiert dank: http://www.whitneykrape.com/2011/07/quick-fix-for-relcategory-tag-in-wordpress/ […]

  4. Catintherain Avatar

    Thank you so much !!!! This fixed 10 errors all at once!

  5. […] Trick, der den eigenen Blog unter TwentyTwelve wieder zur Fehlerfreiheit führt, habe ich in diesem Artikel […]

  6. Rich Amor Avatar

    Thank you, It solved my problems

  7. […] vorab einen sauberen Quellcode haben, wenn auch hier als experimentell zu betrachten. Dank diesem Fix hab ich den Code valide […]

  8. skino_c Avatar
    skino_c

    YESSS!!!
    thanks!

  9. Dan Harden Avatar
    Dan Harden

    Thanks, this was a big help.

  10. […] sono imbattutto in questo articolo che definisce chiaramente il problema e ci aiuta a […]

  11. […] 原文地址:http://www.whitneykrape.com/2011/07/quick-fix-for-relcategory-tag-in-wordpress/ […]

  12. Andrew Avatar

    Thanks Whitney, This was handy to cut down on the long list of errors

  13. […] add_filter( 'the_category', 'add_nofollow_cat' ); function add_nofollow_cat( $text ) { $text = str_replace('rel="category tag"', "", $text); return $text; } Code Source […]

  14. Ashley Avatar

    Thank you so much!

  15. John Avatar

    This worked thanks Whitney! I don't understand why WP is releasing code that includes this tag if it isn't official yet…

  16. Torsten Avatar

    Very helpful for me, too. Invalid plugins for WordPress are almost the normal case, but WordPress itself being invalid was a shock to me. Now, after following your workaround, my blog passes the W3C validator test again. Thank you!

  17. Johan Avatar

    Great! Just what I was looking for. Just validated my first HTML5 WordPress theme, just to notice that annoying error :)

    1. Whitney Krape Avatar

      Glad I could help! It is a bit of an annoying quirk.

  18. […] Jeżeli chcemy mieć skórkę zgodną ze standardami HTML 5 musimy w jakiś sposób pozbyć się wartości category. Przeszukując internet, trafiłem na rozwiązanie na stronie Withney Krape. […]

  19. Simon Vincent Avatar

    Excellent! That has saved me from my nightmare lol.

    Presuming, from your modifications, that the search engines would now ignore the nofollow attribute in that code?

    1. Whitney Krape Avatar

      Exactly, WordPress adds the categories but without the rel="nofollow" so a search engine will still move through those links when indexing.

Leave a Reply to Bhushan Cancel reply

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