A while back I shared a simple tip on how to add a Share on Twitter link to your WordPress blog…
<a rel="nofollow" href="http://twitter.com/home?status=<?php echo urlencode("Currently reading: "); ?><?php the_permalink(); ?>" title="Share this article with your Twitter followers">Tweet this!</a>
But if your URL’s are too long and you’d like a more concise Tweet — there are a few other options for doing this as well (without using plugins).
To keep your domain in the URL, you can easily use WordPress’ built in “ugly permalink” feature to reduce the size of your URL. The ugly permalink is automatically assigned to each post as it’s ID in the database and is also automatically linked to whatever pretty permalink structure you’re using.
http://www.casadeblundell.com/jonathan/p?=666 automatically directs the reader to
http://www.casadeblundell.com/jonathan/west-wing-dvd/
So to build a link, the key is getting the post ID number (the number after ?p=) for each post using the_ID.
Your code will look something like this…
<a rel="nofollow" href="http://twitter.com/home?status=<?php echo urlencode("Currently reading: "); ?><?php the_title(); ?> http://www.casadeblundell.com/jonathan/?p=<?php the_ID(); ?>"> title="Share this article with your Twitter followers">Tweet this!</a>
(Be sure you replace my domain with yours.)
Or another option for shorter URL’s is to use the wp.me short URL from WordPress.com.
To do so, you’ll need to install the WordPress.com stats plugin on your site (which is a nice plugin to have regardless).
Once the plugin is installed, be sure and activate the wp.me option in the WordPress.com Stats settings. (Plugins > WordPress.com Stats and then select the box next to “Publish WP.me shortlinks as metadata”)
Now that that’s completed you can add the code to your pages.
<a rel="nofollow" href="http://twitter.com/home?status=<?php echo urlencode("Currently reading: "); ?><?php the_title(); ?> <?php echo wp_get_shortlink(); ?>"> title="Share this article with your Twitter followers">Tweet this!</a>
There you have it.
Personally I’m using the wp.me option right now for most of my sites. But which option do you prefer?
And of course, if you found this helpful, please share via the social media buttons below. Thanks!