Modify the Tweetable WordPress plugin

This plugin hasn’t been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues when used with more recent versions of WordPress.

The other day I started to think about all these URL shortening services out there. And I’m not a huge fan.

Now, if I had a short URL for my site, I’d be okay with that. But hoping that these link services will be out there for ever, or just using someone else domain, not that cool… For instance, if the domain AUST.IN was available (and yes, I’ve checked), that would be a great domain to shorten links for my site (or just move primarily to it :)). But it’s not, so I’ve been using bit.ly.

Ok, so, for regular links (not on my site, or not a page/post of mine) I’ll most likely continue to use the service. But did you know that WordPress technically has a shorten service in every install? Remember your default permalinks domain.com/?p=12? Yeah, that’s a lot shorter than your current permalink structure, correct?

Using it to your benefit

Now when posting any link to twitter that may involve a new post on your WordPress install, just have a look at the post id:

Usually found in your URL box after publishing or editing you post.

http://domain.com/wp-admin/post.php?action=edit&post=999&message=10

Then use this: domain.com/?p=ID (replacing “ID” with the post ID number) instead of the full URL!

Using this with Twitter plugins

Ok. There are loads of twitter plugins for WordPress that auto publish to Twitter when you publish a new post. And you may be able to hack into the code of some of them and add in a new shortening server: your own!

I’ve been using quite a few lately, but settled on Tweetable just the other day ( 🙂 )

*I just want to point out real fast that although this hack works for shortening your long URL when publishing to Twitter, it will disable your ability to shorten links when using the dashboard widget.

Also, if Matt updates the plugin all these changes will get overwritten, and you’ll have to download the new files and make the changes again.

Ok..

This next part will be editing two files: 1 mh_twitter_class.php and 2 admin_menus.php.

#1
Find line 390 and add global $post; after the public function:

public function shorten_url($the_url, $shortener='is.gd', $api_key='', $user='') {
	global $post;

Find line 419 and add this code after:

	} elseif ($shortener=="self") {
		$url = url_to_postid( $the_url );
		$response = get_bloginfo('url') . '/?p=' . $url;
	// END

#2
Find line 378 and add this code after:

	<option value="self" <?php if ($setting_url_shortener=='self') { echo 'selected="selected"'; } ?>>SELF</option>

Now upload those to files, or if editing them inside of WordPress, save them. Then apply the new changes in the Tweetable settings page and your done. Next time you post a entry the URL used will be your domain with the default ugly permalink!

One more thing, I noticed that if you’ve got the Add Google Analytics campaign tags to auto-tweets. checked, this trick will not work.