Integrating with WordPress 3.0 Shortlinks Support

The official release of WordPress 3.0 being a bit recent, I’ve had a hell of a time trying to find plugin that supports WordPress 3.0. The idea is to get your short URL instead of the WordPress 3.0 short URL that uses your own domain name when you press the “Get Shortlink” button of a post editor. support in WordPress 3.0

I found the “WP” plugin which looks pretty good but does not yet support WordPress 3.0.

So what does an unsatisfied geek do on a Friday evening instead of having dinner? He finds a solution.

1. Download the WP plugin

2. Fix the plugin code

In file wp.bitly.php, put lines 47-48 in comment:

/*add_action( 'wp',      'wpbitly_shortlink_header' );
add_action( 'wp_head', 'wpbitly_shortlink_wp_head' ); */

If you too are a geek and you need to know, this will make sure WordPress 3.0 continues to take care itself of the HTML response header and the Web page HTML header as per the rel=”shortlink” proposed standard. Otherwise, the WP plugin would add these twice to a page which wouldn’t be clean.

3. Modify your theme’s function.php

Add the following code to your theme’s functions.php file:

/* shortlink */

function get_bitly_shortlink($shortlink, $id, $context, $allow_slugs) {
   if (function_exists('wpbitly_get_shortlink')) {
      $slink = wpbitly_get_shortlink($id);
      if (empty($slink)) {
         $slink = wpbitly_get_shortlink($id);
      return !empty($slink) ? $slink : $shortlink;
   return $shortlink;
add_filter( 'get_shortlink', 'get_bitly_shortlink',10,4);

This code links the plugin code to the new WP 3.0 shortlink feature. It also makes sure that WordPress 3.0 will continue to operate as before if you do not enable the WP plugin or you disable it.

Generate the links from the plugin

So that the “Get Shortlink” button gets you a link (instead of the default permalink), these should be generated once from the plugin’s settings. For new posts new links should be created automatically.

Be aware that visits and crawls to your site will generate links for each visited posts if no link already existed for each visited post. This is due to the fact that the short links are included in the code of each of your page to support new standards.

8 thoughts on “Integrating with WordPress 3.0 Shortlinks Support

  1. Totally appreciate the article, I’ve been a little behind on updating my plugins as of late; work and paying clients have to come before my fun, after all.

    0.2.4 has fixed the lack of wp3.0 support and even includes backwards compatibility for those who are slower to upgrade (if you are one of these people, upgrade! 3.0 is impressive, to say the least!).

    As mentioned in the forums, if you have any suggestions for improving WP I’m all ears.

    • Hi, I’m having a lot of error in my error log:

      [Sun Aug 08 12:21:09 2010] [error] [client] PHP Warning: Missing argument 3 for wpbitly_get_shortlink(), called in /var/www/vhosts/
      tent/themes/twentyten/functions.php on line 126 and defined in /var/www/vhosts/ on line 192

      Argument 2 is missing too.
      Arguments from de wp-bitly.php are:

      function wpbitly_get_shortlink( $shortlink, $id, $context )

      I think my implementation, recomended by Jerome, is missing $id & $context.

      MArk, Jerome: ANy idea?

  2. I can’t find those 2 lines in my wp-bitly.php file. I can see the lines that remove the action of the wordpress’s core function but I can’t find the lines in the plugin file.

  3. Sorry about the spam but I’ve found the lines in another file: “deprecated.php”. I don’t know if it’s working the same way…

  4. Working now!
    Just did it in my deprecated.php file

  5. Working fine for me, now I want to use some ReTweet Button using the shortlink but I cant’t figure out how to echo it.
    Would you please help this amateur?

  6. I can’t find those 2 lines in my wp-bitly.php file. I can see the lines that remove the action of the wordpress’s core function but I can’t find the lines in the plugin.

  7. I am also having a hard time finding that code in the php file… guess I will keep digging?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>