Austin Passy
WordPress developer.
  • About
  • WordPress
    • Plugins
      • SEO Media File Renamer
      • Camera+ Widget
      • YouTube White Label Shortcode
      • Featured Image Column
      • @Anywhere
      • Custom Login
      • Comment Validation Reloaded
      • Eventbrite Shortcode
      • Announcement Bar
      • Hide and Catch Email
    • Themes
      • Rock N’ Rolla
    • Code Snippets
  • Presentations
    • WordCamp
      • Miami
      • Phoenix
      • Los Angeles
      • Portland
      • Orange County
  • Portfolio
  • Contact
  • Categories
    • General
    • WordPress
    • Tutorials
    • jQuery
    • Galleries
    • asides
    • Photos
    • Stuff
    • Uncategorized

Announcement

  • Announcing: Custom Login PRO – Pro version of Custom Login by yours truly.
  • Announcing: Frosty Themes ☃ – Custom built WordPress themes by yours truly.
  • Photographer? Checkout Photography Blog Sites WordPress portfolio made easy
  • I use Dropbox everyday!
  • This site is faster thanks to MAX CDN.
  • NEW: Camera+ WordPress widget get the plugin.
You are here: Home / Snippets / How I hacked Tweetable for a personal URL shortener

How I hacked Tweetable for a personal URL shortener

Pulished February 8, 2010

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.

Posted in Snippets Tagged hack, PHP, Plugin, WordPress

Share How I hacked Tweetable for a personal URL shortener

Tweet

Possibly Related Posts

  • Modifying Tweetable plugin to work with PrettyLinkPro & Twitter Friendly Links
  • Announcing Featured Image Column plugin
  • Announcing YouTube™ White Label Shortcode Plugin
  • Introducing “Hide and Catch Email” Version 0.3
Domain Registrations starting at $9.98*
← Previous Next →

Possibly Related Posts

  • Modifying Tweetable plugin to work with PrettyLinkPro & Twitter Friendly Links
  • Announcing Featured Image Column plugin
  • Announcing YouTube™ White Label Shortcode Plugin
  • Introducing “Hide and Catch Email” Version 0.3

Random photo

  • IMG_0255

Most Viewed

  • Custom Login - 54,297 views
  • Capturing the URL anchor w... - 18,555 views
  • Creating custom metaboxes ... - 15,307 views
  • Add a twitter field to you... - 11,938 views
  • Custom post type "jokes" p... - 9,336 views
  • Starting a blog with WordP... - 8,706 views
  • Adding a custom default gr... - 8,513 views
  • Auto change "WP" and incor... - 7,807 views
  • St Pattys day at the Roxy - 4,434 views
  • Camping at the Eagles Nest... - 4,021 views

Recommendations

Ad Sanity
InMotionHosting
MaxCDN
Namecheap

Recent Tweet

  • Nice rip Sands! #Dodgers 15 hours ago
  • RT @DeFries: Cool plugin to map domains to WordPress pages: Domain Mapping System - wordpress.org/extend/plugins… 20 hours ago

RSS My baseball photo blog

  • Jerry Sands wearing number 30
  • Hershiser 55 bobble head
  • Orel Hershiser bobble head
  • 4 DDGERS: A license plate’s story

Copyright © 1983-2012 Austin Passy.

Powered by WordPress hosted by Inmotion Hosting.

Follow @TheFrosty

    • Login
    • WordPress.org
    • Documentation
    • Support Forums
    • Feedback