WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to add outbound link tracking for links within my posts. But only for links that do not have an img as a child. My code is below but does not add my class to any links in my posts:

    //outbound post links
    //var outbound_post_name = jQuery(this).find('h2.title').text();
    var post_link = jQuery('.post .entry').find('a');
        if( jQuery(post_link).has('img') ){
            //do not add class or tracking if the link has an img
                _gaq.push(['_trackEvent', 'Outbound Link', 'Click', outbound_post_name + 'Post Link', '', false]);

I also need to get the post title for my label but am unsure of how to get it set as "outbound_post_name".

If I remove the "if" statement all links get the class "outbound-link" What am I missing?


share|improve this question
up vote 0 down vote accepted

Have a look at this article -> http://www.optimum7.com/internet-marketing/web-development/dynamic-google-analytics-event-tracking-for-wordpress.html

Also to get the post title of the particular page. You could use the following jQuery ( Assuming you post title is wrapped in tag ).

outbound_post_name = jQuery('h1').html();
share|improve this answer
Thanks for the link, perfect! I know I can grab my title via my h2.title tag on single post pages without problems. But when adding the post title to the vent tracking in category, archive pages I get a bit lost. I think I need to use a combination of parents() and prevAll(). I'll try it out and see what happens. Thanks again! – dkmojo Nov 30 '11 at 16:40
Here is the code that worked for me getting the post title: codevar post_title = $(this).parent().parent().siblings('h2.title').text();code – dkmojo Nov 30 '11 at 16:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.