WordPress.org

Ready to get started?Download WordPress

Forums

Google Analytics for WordPress
Outbound Links XHTML Not Valid - target attribute (5 posts)

  1. Josh Eaton
    Member
    Posted 3 years ago #

    Similar to this issue from 3 years ago:
    https://wordpress.org/support/topic/google-analytics-for-wordpress-outbound-links-xhtml-not-valid?replies=4

    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="http://example.com/" target="" onclick="javascript:_gaq.push(['_trackEvent','outbound-blogroll','http://example.com/']);">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!

    http://wordpress.org/extend/plugins/google-analytics-for-wordpress/

  2. Bernhard Kau
    Member
    Posted 2 years ago #

    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.

  3. Josh Eaton
    Member
    Posted 2 years ago #

    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?

  4. Bernhard Kau
    Member
    Posted 2 years ago #

    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.

  5. Josh Eaton
    Member
    Posted 2 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic