WordPress Shortlinks

Update: June 18th, 2010
With the release of WordPress 3.0 this solution no longer works, however you are still able to provide a short link to your post by using the_shortlink template tag.

Thanks to services such as Twitter, URL shorteners seem to be all the craze these days. Especially when it comes to trying to keep your precious characters to a minimum.

With the release of WordPress 2.9 and an update to the WordPress.com stats plugin the wp.me shortlink feature is now available to all self-hosting users of WordPress.

How to get your own shortlinks

To get shortlinks working on your own site you’ll first need to head over to WordPress.com and sign up for an account (so you can get your hands on the all powerful API key) then simply proceed to download and install the WordPress.com stats plugin.

Once you have the plugin installed you’ll see a ‘Get Shortlink’ button on the ‘Edit Post’ screen.

Displaying them on your site

If you’re like me and want to display the sexy new shortlinks on your site all you need to do is add this little piece of code within the loop of your theme.

<?php if (function_exists('get_shortlink')) { ?>
    <a href="<?php echo get_shortlink($post);?>"><?php echo get_shortlink($post); ?></a>
<?php } ?>

Keep the stats but remove the shortlinks

Now I know there are people out there who are already using plugins to create shortlinks for their content and are more than happy to continue using them. In fact they may even get a little upset that this feature has been included in the WordPress.com stats plugin.

So if that’s you and you’d like to exclude the WordPress shortlink feature but keep the stats working then just add this to the functions.php file in your theme folder.

remove_action('wp_head', 'shortlink_wp_head');

There's been one comment so far...

Thanx for the tip, I was looking for a way to deactivate the shortlink in my head. Mostly because the links return: “Sorry, we could not resolve that url.”

So thanx WordPress.com for the shortlink, but maybe it would be good if it actually worked.

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=""> <strike> <strong>