Google Analytics by MonsterInsights
[Plugin: Google Analytics for WordPress] Failed XHTML Strict validation (3 posts)

  1. 3dolab
    Posted 5 years ago #

    Hello, since I've declared my site as XHTML 1.0 Strict, when the Google Analytics plugin adds the tracking code to the blogroll links, it breaks the validation by inserting the target property in the anchor link along with the onclick javascript code.

    It was easy to solve it, by simply replacing the hook:
    $bookmarks[$i]->link_target .= $trackBit;
    $bookmarks[$i]->link_rel .= $trackBit;

    so the JS tracking code could be appended without hassle

  2. 3dolab
    Posted 5 years ago #

    I believe the fix won't work

    The output looks like:
    <a href="http://mysite.com" rel="friend, external, nofollow&quot; onclick=&quot;javascript:_gaq.push([...]);">

    So I reverted back to the official code, the tracking now runs again but the page still fails the XHTML validation:
    <a href="http://mysite.com" rel="friend, external, nofollow" target="" onclick="javascript:_gaq.push([...]);">

    How could the JS code be injected into the rel attribute and preserve formatting of double quotes as it does with target??

  3. 3dolab
    Posted 5 years ago #

    the only way to do that requires to edit wp-includes/bookmark-template.php and replace
    $rel = ' rel="' . esc_attr($rel) . '"';
    $rel = ' rel="' . $rel . '"';

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Google Analytics by MonsterInsights
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic