Support » Plugin: Google Analytics for WordPress by MonsterInsights » [Plugin: Google Analytics for WordPress] Outbound Links XHTML Not Valid – target attribute

  • Similar to this issue from 3 years ago:

    My site is failing W3C validation due to the outbound link tracking. When I disable it, the site validates. It only seems to affect outbound links in my blogroll in the sidebar. No other outbound links are affected.

    It lists the error as the target attribute of the links “syntax of attribute value does not conform to declared value.” The links show up like this:

    <li><a href="" target="" onclick="javascript:_gaq.push(['_trackEvent','outbound-blogroll','']);">Example link</a></li>

    The validator fails on target="". I assume this should be ‘_blank’, ‘_top’, or ‘_self’ or the target attribute shouldn’t be added at all. When I turn off outbound tracking, these links do not have a target attribute.

    I’m not sure if this is the same issue someone saw before, but would you know how to fix it? Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • I had the same issue yesterday trying to validate my blog. I dived into the sources of the plugin and the WordPress core that creates the blogroll. Unfortunately he used the only possible way to add the code. There is no filter to add additional attributes to a blogroll link tag. So my solution was using a filter and removing the empty target attributes:

    function remove_empty_target($content){
    	return str_replace('target="" ', '', $content);
    } add_action('wp_list_bookmarks', 'remove_empty_target');

    Just include this little snippet into the functions.php file of your theme and the target attributes should be removed.

    Thanks for the workaround. This still feels wrong though. You can specify when creating a link in your blogroll what the target should be. Now, I haven’t dived into the code, but I would imagine that this is a bug, since the blogroll shouldn’t be creating invalid HTML on purpose, right?

    The blogroll does not create the invalid HTML, it’s the Google Analytics for WordPress Plugin. But as I mentioned, the author had to include the onclickk attribute somehow. And the least terrible way was using the target attribute for this job. So as soon as there will be a filter for the blogroll links included into the WordPress core we can fix the issue in a nice way. Feel free to open a ticket for that issue.

    OK great, yes, I misunderstood you, but I get it now. Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: Google Analytics for WordPress] Outbound Links XHTML Not Valid – target attribute’ is closed to new replies.