WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Widgets - don't validate links in xhtml (16 posts)

  1. ternef4339
    Member
    Posted 7 years ago #

    I have activated the Automattic Widgets and when I validate my blog at W3C I got following error message:
    -------------------------------------------------------
    1. Error Line 481 column 8: ID "links" already defined.
    <li id="links" class="widget widget_links"><h2 class="widgettitle">www</h2>

    An "id" is a unique identifier. Each time this attribute is used in a document it must have a different value. If you are using this attribute as a hook for style sheets it may be more appropriate to use classes (which group elements) than id (which are used to identify exactly one element).

    2. Info Line 472 column 8: ID "links" first defined here.
    <li id="links" class="widget widget_links"><h2 class="widgettitle">Forum & N
    --------------------------------------------------------
    The Widget doesn’t work with categories for links and I have tried to find some tip when I search for my problem here on the support forum. But I didn't find some answer. Is it anyone here who has an idea of solution?

    http://www.utmattningsdepression.net/bloggsida/index.php?cat=3

  2. Alex Cragg
    Member
    Posted 7 years ago #

    look in the widget php file and find the part that has id="links", and change it to class="links" wherever it occurs. Classes can be defined more than once.

    now change your css from #links to .links

  3. ternef4339
    Member
    Posted 7 years ago #

    Oh, I forget to say that I have looked in the widget.php file but I can't find id="links" there.

  4. ternef4339
    Member
    Posted 7 years ago #

    I find the solution by myself. I changed line 47 in the widgets.php file

    from

    'before_widget' => '<li id="%1$s" class="widget %2$s">',

    to

    'before_widget' => '<li class="%1$s" >',

    and it has been w3c valid in XHTML.

  5. docwhat
    Member
    Posted 7 years ago #

    That fix removes the very useful ID attribute for all widgets!

    An even better fix is to add this line before 362:
    $before_widget = preg_replace('/id="[^"]*"/','id="%id"', $before_widget);

    This lets wp_list_bookmarks do it's thing. You end up with links, as before widgets, like "linkcat-16".

    Ciao!

  6. Dut
    Member
    Posted 7 years ago #

    Hi !
    Thanks for this very usefull tip !
    I just here to update it :

    • - On wordpress 2.2.1 you have to add :
      $before_widget = preg_replace('/id="[^"]*"/','id="%id"', $before_widget);
      before line 397 (after the } else { )
    • - there are 2 "widgets.php" files, the one we are talking about is : wordpress/wp-includes/widgets.php
  7. skarabaeus
    Member
    Posted 6 years ago #

    It seems in WordPress 2.3 this value is still not solved and needs manual adjustment:

    By commenting out line 402 in wp-includes/widget.php the original ID and class arguments from wp_list_bookmarks is used. After, the XHTML Validation is correct again!

    BR
    Stefan

  8. jrothe
    Member
    Posted 6 years ago #

    I found this post today as I was trying to validate the xhtml code in my WordPress site.

    I read through the chain of comments, it looks like one of the last two solutions for editing the widgets.php should solve the problem of having unique id's when using categories in the blogroll.

    I tried commenting out line 402, and that didn't seem to change anything, and I also tried to add the line of code listed above inside the closing else tag, but that didn't seem to work.

    Is there something else I can do to get my validation working for this aspect? Has anyone else commented out line 402 and had the blogroll widget use unique id tags?

  9. jrothe
    Member
    Posted 6 years ago #

    Commenting out line 402 did end up working...my page does validate now. I don't know what I ended up changing by commenting this line out, but it worked for this purpose.

    Yesterday when it didn't work, I realized my lines were off because I had added the other line in above in the else function. When I looked at it again today, I realized I needed to comment out the line that looks like this;

    'category_before' => $before_widget, 'category_after' => $after_widget,

  10. Krofinzki
    Member
    Posted 6 years ago #

    I just want to add that the "commenting out line 402-solution" works perfectly. I guess the wordpress theme should remove that line in the next version.

  11. phocks
    Member
    Posted 6 years ago #

    This is still an issue as of 2.5-RC2 hmmm...

  12. csl749
    Member
    Posted 6 years ago #

    Yep, would be nice to have this little issue taken care of.

  13. 0verdose40
    Member
    Posted 6 years ago #

    wordpress 2.5, bug still in :/

  14. cyelz
    Member
    Posted 6 years ago #

    In WP 2.5 the bug's still there.. I used the "commenting out Line 402" method:

    'category_before' => $before_widget, 'category_after' => $after_widget,

    but this time it's not Line 402, but Line 433.

  15. leej
    Member
    Posted 6 years ago #

    Thanks cyelz, the fix works. :-)

  16. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    Sigh. I reported this 11 months ago and it still didn't get into 2.5. Annoying, that is.

    http://trac.wordpress.org/ticket/4287

Topic Closed

This topic has been closed to new replies.

About this Topic