Support » Plugins » [Plugin: Sociable] Using shorter URLs for TwitThis

  • Warning: I taught myself coding from looking at the source. I’m probably doing something wrong here. If not wrong… inefficient, at least.

    The problem: Really long URLs can eat up into your tweet. Additionally, you have the problem of the same words from the title being repeated in the URL. Redundant, like Duran Duran Duran.

    The solution: using “ugly” permalinks ( ) There probably is a way to use a link shortener, but why go to that extent when there’s a built in short URL in WP. Unless your URL is

    Step 1: Changing the link
    Open wp-content/plugins/sociable.php and find the declaration for TwitThis. Change the second line to
    'url' => '',
    There’s probably a better way to replace with a variable(?), but I wouldn’t know. You could customize the status to include an @YourTwitterId, but hash tags don’t seem to work, for some reason.

    Step 2: Defining POSTID
    Now, you need to define POSTID. Scroll down to `// Load the post’s data
    and add$postid = $post->ID;` on a new line after the $blogname definition.
    Next, scroll down to `$url = str_replace(‘PERMALINK’, $permalink, $url);
    ` and add this line below it:
    $url = str_replace('POSTID', $postid, $url);

    If you update the plugin, be sure you back up the changed file, and make the changes to your new file.

Viewing 5 replies - 1 through 5 (of 5 total)
  • don’t hack around – use a plugin
    it will do this stuff for you plus add any social link you desire

    Isn’t that a different plugin altogether?

    The hacking was for a specific plugin, I should have mentioned it.

    I was trying to figure out why Sociable didn’t already use shorturls, and then came across your hack. I followed your directions and it works beautifully.

    Thank you for posting it.

    here is my workaround to get shorten url and implement in sociable plugin:

    step 1: add following lines in functions.php
    // Ondemand function to generate tinyurl
    function getTinyUrl($url) {
    $tinyurl = file_get_contents(“”.$url);
    return $tinyurl;

    step 2: open sociable.php

    – in block “// Load the post’s data” I added line
    $turl = getTinyUrl(get_permalink($post->ID));

    – then few lines below, just below “$url = str_replace(‘EXCERPT’, $excerpt, $url);” I added following line
    $url = str_replace(‘TINY’, $turl, $url);

    – and at the end in block “$sociable_known_sites = Array(” I found and change ‘TwittThis’ to following
    ‘TwitThis’ => Array(
    ‘favicon’ => ‘twitter.png’,
    ‘url’ => ‘’,

    Works for me 🙂

    works, thank you.

    but: generates a new tinyurl every time the corresponding article is viewed already, so if a blogpost has 500 reads/views, 500 “new” tinyurls will be generated. each time the sociable buttons are displayed.

    i can’t think of a workaround for this, actually, just thought i’d mention it. this somehow doesn’t “feel okay” with the tinyurl- (or any other shortening-) service, actually. 😐

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Plugin: Sociable] Using shorter URLs for TwitThis’ is closed to new replies.