At work I’m adding the social media sharing tools into one our mandatory publications. One thing I really wanted to do was to have was quote boxes that had sharing buttons which when you pressed the Tweet button instead of getting the normal “page title http://t.co/mehmeh via @addthis” that AddThis supplies by default it would tweet the quote and a link to exact box. I tried to use the “addthis_share” method that the AddThis API suggests, one problem arose though. With multiple instances of the addthis_share (even when in a for loop) the buttons only seem to use the last definition. I looked into it a bit more and found that you can use attributes in the AddThis parent element and the Twitter button element.
To get this solution working on your WordPress theme you need to firstly know a little HTML and PHP. WordPress uses a thing called ‘The Loop’, this spits out your posts on the page. You should see a while loop like this
<?php while (have_posts()) : the_post(); ?>. Inside this while loop is your post template, I decided to put them at the end of my posts so I added it right before the end of the while loop (which looks like this:
<?php endwhile; ?>). The code is below, the PHP tags generate the URL and title for you so you can just drop it straight into your templates.
<ul class="addthis_toolbox addthis_default_style" addthis:url="<?php the_permalink(); ?>" addthis:title="<?php the_title(); ?>">
<li><a class="addthis_button_tweet" tw:via="colinwren"></a></li>
<li><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a></li>
<li><a class="addthis_counter addthis_pill_style"></a></li>
You’ll need to change the tw:via attribute value to your own Twitter account name and if you don’t like the layout I use you can use the AddThis API reference for more information on layouts.