HowTo – Patching Twitter Tools To Use Short PostID URLS

Filed under: Wordpress Tips

The WordPress plugin Twitter Tools is one of the most popular plugins and is used by almost every wordpress site out there. It offers the ability to announce new posts on twitter and also retrieve your tweets for display on your WordPress Website.

The main reason that most sites use this tool is to attract visitors and although the Twitter Tools plugin comes with the option to use a third party url shortening service it means a signup for api access and it also means your tweets will be pointing to an outside site instead of your own.

Additionally most sites use a permalink structure that uses the post title in the URL. This is the difference of www.npsites.com/1234/howto-installing-your-server.html vs www.npsites.com/?p=1234

What many people forget is that although they are using the pretty permalink with human readable information the basic /?p=1234 url is still functional. In addition when visitors use the shorter PostID url they are auto forwarded to the long url.

For some time now Twitter Tools has not offered the ability to use the shorter PostID urls. This can be a problem when a visitor ReTweets you on Twitter or when they copy the url in your tweet to their own post.

Third party URL Shorteners are great we use TinyURL on a daily basis but when you use these urls you do not get backlinks to your site. This is a waste of your resources because you want as many of your links out there on the internet pointing directly at your site to improve your search engine rank.

And if you did not notice Twitter Tools will Fail if you are using long Post Titles and Pretty Permalinks when the Tweet is over 140 characters. That means most of your posts may not even make it to Twitter.

Anyway that is the reason behind this hack.

To implement the patch open the Twitter Tools Main Plugin file.

On line 489 of file twitter-tools.php you will find the line.

(in your text editor search $url is the fastest way to jump there)

[php]

$url = apply_filters(‘tweet_blog_post_url’, get_permalink($post_id));

[/php]

CHANGE THAT LINE TO

[php]

$url = apply_filters(‘tweet_blog_post_url’, get_settings(‘home’) .’/?p=’. $post_id);

[/php]

Make sure thats all on one line like the original.

Ok that is all you have to do but remember that if you apply this hack you will need to either never upgrade again… or apply it again when you download a new version.

I took a bit of time to try and get a plugin / filter going but it seems that $post_id is not available to an outside plugin..

I will probably take another look in a few days and then offer a plugin but this patch / hack should get you by in the mean time.