Support » Plugins » [Plugin: Sociable] Shortened URLs

Viewing 10 replies - 1 through 10 (of 10 total)
  • Mark me down for a yes on the integration. I am about to google it and if no solution is available, guess we will just have to hack-n-roll our own, eh? I’ll post my progress.

    Found a solution (in less than the time it took to write that last post—doh!) Check out the end result here: and how it’s done here:


    I posted a fix on that webexpedition post linked above, but it seems that Nikola aka Colaja from Nis, Serbia removed it. Very well, I will post it here.

    The issue I faced when using Coloja’s hack was that it generated a shortened url ( in my case) during the page loop. So, on the main page, where we are showing the latest 10 posts… the loop hit the API, get a shortened URL 10 times, adding about 11 seconds to the load time of homepage–not very efficient. What I opted for was to pass permalink to a custom bit2twitt.php file that would the link only after the user clicked on it, then redirect to twitter, passing the shorted url.

    To sum up what you need to do:
    1. Open sociable.php and find the following block:

    'Twitter' => Array(
    		'favicon' => 'twitter.png',
    		'awesm_channel' => 'twitter',
    		'url' => '',

    and change it to:

    'Twitter' => Array(
    		'favicon' => 'twitter.png',
    		'awesm_channel' => 'twitter',
    		'url' => 'bit2twit.php?url=PERMALINK',

    2. create a new file called bit2twit.php with the following code:

    $url = $_GET['url'];
    // Ondemand function to generate dynamic urls
    function getBitlyUrl($url) {
        // fill up this 2 lines below with your login and api key
        $bitlylogin = '<your login goes here>';
        $bitlyapikey= '<your api key goes here>';
        // you dont need to change below this line
        $bitlyurl = file_get_contents(''.$url.'&login='.$bitlylogin.'&apiKey='.$bitlyapikey);  
        $bitlycontent = json_decode($bitlyurl,true);
        $bitlyerror = $bitlycontent["errorCode"];
        if ($bitlyerror == 0){
            $bitlyurl = $bitlycontent["results"][$url]["shortUrl"];
        else $bitlyurl = $url;
        return $bitlyurl;

    3. place the bit2twit.php file you just created in your wordpress root and you are golden.

    I’m sorry, but… wouldn’t this hack be wiped out by future updates to Sociable?

    I wrote a patch to support with every service (not only twitter) :

    I got the following error (I’ve hidden part of username and api):

    Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /home/victorar/public_html/bit2twit.php  on line 10
    Warning: file_get_contents(*********&apiKey=R_9db*********1ce3f3ca57b) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /home/victorar/public_html/bit2twit.php on line 10
    Warning: Cannot modify header information - headers already sent by (output started at /home/victorar/public_html/bit2twit.php:10) in /home/victorar/public_html/bit2twit.php on line 24

    What am I doing wrong here?

    Thanks for any help.

    This was my take on this: shortening


    victoraroestad> You server doesn’t allow file_get_content to get the content of external url. You try to use HTTP or curl or configure your server (if you have access to it).


    i have the same problem of file_get_content … but short url work with other plugin… Have you an idea ?


    you can host and customize short urls on your own site using the plugin by StumbleUpon, apparently. I’m having a hard time understanding how to configure it, but it’s free if anyone wants to give it a go.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘[Plugin: Sociable] Shortened URLs’ is closed to new replies.