Hacking WordPress shortened links and Twitter Tools

Jun 01 2009 Published by JuanO under Blog

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!

2 responses so far

Before Hanna pays a visit:

Sep 05 2008 Published by JuanO under Blog

I’ve been monitoring the Doppler, watching Hanna travel along the coast and, finally, towards us.   It seems a lot bigger then it did before, but I am sure that is my imagination.   I’m a little excited and a little nervous.   This is the first hurricane that we’ve ever experienced.   I imagine this is what people feel like when they experience their first earthquake.

Anyway, in case the power goes out, we will lose the house phone.   (side note: I know I said I was going to cancel it, but rather then pay cancellation fees, I thought I would wait until the 1st of Oct.   Rest assured, it will be canceled then.)   Our cell phones might not get reception through the thick cloud cover, but sometimes when you can’t get a voice signal, you can get a data signal.   If I have a data signal than i will send updates, if any, to my Twitter page.

Right now we are under flash flood warning, high wind warning, and tornado warning.   It doesn’t seem like the hurricane will come near us, even though it looks like it might from the satalite images, so we should just a get a few inches of rain and lots of wind.   Hopefully no tornadoes, as they can be hard to see at night!   The wind will more than likely kill our power, but, like I said before, I am more worried about the trees in our backyard.   Most likely they will survive, if not, then hopefully they will fall away from the house.

We’re all set up downstairs, our supplies are ready, and it will soon be time for bed.   I don’t know if I’ll be able to sleep.   If there is enough light outside, I plan on taking pictures of the storm.   The ones I take will go up on my Flickr page, too, so check that one out if you can.

I just checked out the Doppler again.   It crazy watching it roll in like a gigantic cloud.   The beginning will be here in about 15 minutes.

In other news, Chris told me today he wants to play World of Warcraft.   I’ve actually missed playing it, so resigned up and I am about to play it right now on the laptop.   That is, until I get tired or the power goes out.   It’s been a few months since I’ve played, this should be fun.

No responses yet

Switch to our mobile site