Alex Priest

Making the Tweet Button Work on WordPress

| 4 Comments

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>

Author: Alex Priest

Alex Priest is the DC Community Manager for @Uber_DC. He’s been called “hilariously driven” and is a lover of social media, politics, transportation, technology, design, bicycling, and more. Alex loves living, learning, and collaborating in what he considers one of the best cities in the world: DC. His goal in life? To simply tell good stories when he’s old. Follow him on Twitter @alexpriest.

4 Comments

  1. Pingback: Tweets that mention Making the Tweet Button Work on Wordpress | alexpriest.com -- Topsy.com

  2. …or you could just download the plugin. http://bit.ly/bwWzvq

  3. Haha but plugins will slow down your site, and could problems with future upgrades ;-) Couple lines of HTML code can easily be deleted, and are super, super simple.

Leave a Reply

Required fields are marked *.

*