WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: Sociable] Using shorter URLs for TwitThis (6 posts)

  1. ousep
    Member
    Posted 5 years ago #

    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 (example.com/&p=34 ) 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 somethingreallyreallylong.com/anevenlongerblogtitle/

    Step 1: Changing the link
    Open wp-content/plugins/sociable.php and find the declaration for TwitThis. Change the second line to
    'url' => 'http://twitter.com/home?status=TITLE http://example.com/?p=POSTID',
    There's probably a better way to replace http://example.com 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.

  2. Samuel B
    moderator
    Posted 5 years ago #

    don't hack around - use a plugin
    http://wordpress.org/extend/plugins/tweet-this/
    it will do this stuff for you plus add any social link you desire

  3. ousep
    Member
    Posted 4 years ago #

    Isn't that a different plugin altogether?

    The hacking was for a specific plugin, I should have mentioned it.
    http://wordpress.org/extend/plugins/sociable/

  4. geekygrrrl
    Member
    Posted 4 years ago #

    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.

  5. colaja
    Member
    Posted 4 years ago #

    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("http://tinyurl.com/api-create.php?url=".$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' => 'http://twitter.com/home?status=TINY',
    ),

    Works for me :)

  6. frank93
    Member
    Posted 4 years ago #

    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. :-|

Topic Closed

This topic has been closed to new replies.

About this Topic