Hack the Sociable Plugin to Use Your Own URL-Shortener

by Kurt Milam on February 12, 2010
http://xioup.com/s/356

Are you running a hosted WordPress blog? Do you have your own, branded link-shortener? Do you use the awesome Sociable plugin? If you answered "yes" to all of those questions, we’ll show you how to strengthen your online brand with humans and search engines in a few simple steps. If you don’t have a link-shortener yet, we’ll show you how to set that up, too!

Three Reasons You should Follow this Guide:

  1. Strengthen Your Online Brand with Humans – your posts that are shared via Sociable will have shortened links with your domain name, not someone else’s (bit.ly, awe.sm, etc.).
  2. Strengthen Your Online Brand with Search Engines – see point #1. Every link to your branded URL-shortener is another link to your domain for search engines to find.
  3. It’s Easy – If you’re comfortable uploading files to your webserver via FTP and changing a little PHP, you can be up and running in about 15 minutes!


Set Up Your Branded Link-Shortener

If you haven’t set up your own link-shortener yet, follow the easy instructions here, first. To get the shortest URL possible, we suggest you use a one-letter directory name for your shortener.

We’ve named our link-shortener directory ‘s’ (short for ‘short’). As an example, the shortened link to the article you’re currently reading is: http://xioup.com/s/356.

Modify the Sociable Plugin (version 3.5.2)

Compatibility: We’ve tested the following steps on a WordPress 2.9.1 hosted blog running on a linux/Apache server with the 3.5.2 version of the Sociable plugin. If you’re running another setup, YMMV.

Fair Warning: If you’re not comfortable mucking around in PHP, you may want to move on. There’s a chance you’ll break your blog or your plugin if you continue!
If you’d like to hire one of our experts to take care of this or other technical customizations to your WordPress site, contact us today!

Download the sociable.php file from your web server via FTP. You should find the file in the following directory: wp-content/plugins/sociable/ . Make a backup copy of the file with the filename ‘sociable.bak.php’ and upload it back to the sociable directory on your web server (this way you have a backup in case something goes horribly wrong). Open sociable.php in your favorite text editor.

Now you’re ready to start:

  1. Find the following line in sociable.php (in our copy of the file, it’s on line 744):
    $permalink = urlencode(get_permalink($post->ID));
  2. Change the line to this (replace [Link Shortener URL] with the URL to the link-shortener you created earlier).

    For xioup’s shortener, that’s ‘http://xioup.com/s/’:

    $permalink = urlencode('[Link Shortener URL]'.$post->ID);

Extra Bonus: You can add ‘RT @[yourtwitteruser] ’ in front of Sociable tweets that come from your blog like this:

  1. Find the following line in sociable.php (in our copy of the file, it’s on line 540):
    'url' => 'http://twitter.com/home?status=TITLE%20-%20PERMALINK',
  2. Change the line to the following (replace [yourtwitteruser] with your actual twitter user name).

    For xioup, that’s ‘xioup’:

    'url' => 'http://twitter.com/home?status=RT @[yourtwitteruser] TITLE%20-%20PERMALINK',

Last Step:

Upload sociable.php back to your web server and test that everything’s working by clicking on a few of the Sociable icons and testing the URLs Sociable is sending to the various social media services.

If you can’t get it to work, rename sociable.bak.php on your server back to sociable.php , and you’ll have your old, unhacked version of Sociable running again.

Parting Words

The next time you upgrade to a new version of Sociable, your changes will be lost. I keep my plugins up-to-date, so I’ll make sure to keep this post updated with specific instructions for new versions of Sociable. In other words, you should really bookmark this page ;-)

If this article was helpful, please share it with the Sociable links below. You’ll be testing xioup’s hacked version of Sociable and our branded link-shortener at the same time!

Share this page:
  • Facebook
  • Twitter
  • LinkedIn
  • Identi.ca
  • del.icio.us
  • Faves
  • Google Bookmarks
  • Diigo
  • Add to favorites
  • Technorati
  • Ping.fm
  • Reddit
  • Digg
  • StumbleUpon
  • Posterous
  • Tumblr
  • Live
  • email

Related posts:

  1. WPtouch WordPress Plugin: xioup.com is IPhone, Android, Blackberry & PalmOS enabled

{ 1 comment… read it below or add one }

John January 23, 2011 at 21:09

I’m using this for my site. It works wonderfully but make sure to put %20 instead of spaces for html validity.

status=RT%20@crackpixels%20

Leave a Comment

Notify me of followup comments via e-mail. You can also subscribe without commenting.

Previous post:

Next post: