Hacking WordPress shortened links and Twitter Tools

Uncategorized

This shortened URL business really has gotten out of hand.  Morning Toast wrote a rant about it a few days ago and it got me thinking about their usefulness.  He also twittered about Flickr’s own URL shortener as well.  Although Flickr uses a different domain name for these shortened URLs, the link is still obvious about it’s context; it is a Flickr image.

I found out about this idea of using “rev=canonical” within a link.  I’m still trying to understand the whole concept: essentially if a link is created, a shortener service checks if the link owner has already shortened it.  If the owner has indeed shortened it, the shortener service will provide the owner’s short URL to the request-or.  That’s way to complicated for me, but it would be nice have my own shortened links when I post them to a service like Twitter.

Then it hit me.

I remembered that when you first install WordPress, “pretty” permalinks are deactivated.  Running in this default mode, a post link looks like this: http://guamaso.com/?p=293.  It still doesn’t have the context of the post itself, but at least now you know that it is related to The Guamaso.  It may not be shorter than http://bit.ly/1m4Qp, but the added context is worth it to me.

So how do I implement this “built-in shortener?”  I use Twitter Tools to automatically send a blog post to Twitter.  Why not use Twitter Tools to send the short URL instead of the pretty URL!  I changed a few things on line 466:

$shorturl = get_bloginfo(‘url’);
$shorturl .= “/?p=”;
$shorturl .= $post_id;

LINE 466: $url = apply_filters(‘tweet_blog_post_url’, $shorturl);

UPDATE: The items in bold are what I changed / added.

I sent a a test “twit” to Twitter earlier and it worked (actually, I initially forgot to add the “p” but it’s in there now.).  So instead of passing the full permalink that will get shortened by Twitter anyway, it now sends the shorter WordPress URL that starts with my domain name.  Boom.

I don’t think a reader can find the post’s ID without direct access to the Admin area, so providing this short link for the reader to use is the key to making this method successful.  I’d also like to see more plugins that use these shorter links when posting to Twitter.  It makes way more sense then letting Twitter make the decision.  On the other hand, blogs that post 10+ entries a day may out grow it in a few years… but hey, maybe by then we’ll jump to the next social trend anyway.

UPDATE 2: Scratch everything I just said!  Don’t edit Twitter Tools, instead download the Twitter Friendly Links plug-in.  It works with rev=canonical, Twitter Tools, and it will also add the short link on your posts for your readers.  The best part is it will make the link shorter than with the hack I explained above.  Instead of http://guamaso.com/?p=293 it will be http://guamaso.com/293. Good plugin, give it a try!

Advertisements

2 thoughts on “Hacking WordPress shortened links and Twitter Tools

  1. looks like a great idea, i’m no supercoder – can you explain exactly where you placed/replaced that code in the twittertools php to utilize the internal shortner?

  2. I’m no super coder either, I’m still learning the finer stuff. I edited the post to show what I changed. If you have the most recent version of Twitter Tools installed, just go to line 466 and add the first three lines between line 465 and 466. Then change line 466 so that it looks like the one above. Save and boom, you’re good to go. Good luck!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s