Making the Tweet Button Work on WordPress 3
This is super-basic for anyone who’s been using WordPress for a while, but I thought I’d just throw out a quick addendum to this Mashable post on how to integrate the new official Tweet button (see at the bottom of this post) with your CMS.
For people running WordPress.org installations, it’s super easy to install–you just drop the line of code in where you want it to go. For me, for example, it goes in a tiny footer at the bottom of each of my posts.
The only minor hiccup I had when installing it was getting it to tweet the correct entry title and URL when someone clicked on the button from my homepage. Because you’re technically on my homepage, the button’s default settings led users to tweet nothing but my homepage and the URL for alexpriest.com. Thankfully, it’s a super, super quick fix.
The line of Twitter code is simple:
<a href=”http://twitter.com/share” class=”twitter-share-button” data-count=”horizontal” data-via=”alexpriest”>Tweet</a>
This, by itself, will do nothing but create a Tweet button sharing the current page. In order to get it to tweet the correct post (even from the homepage), you need to add these two bits of code to the link HTML in the Twitter button:
data-text=”<?php the_title(); ?>” data-url=”<?php the_permalink() ?>”
This makes it so that the text of the tweet is the title of your entry (<?php the_title(); ?>) and the link is the permalink to that post (<?php the_permalink() ?>). In the end, my final code looks like:
<a href=”http://twitter.com/share” class=”twitter-share-button” data-text=”<?php the_title(); ?>” data-url=”<?php the_permalink() ?>” data-count=”horizontal” data-via=”alexpriest”>Tweet</a>




