Use WP.ME As URL Shortener
You may have already noticed that I am using the wp.me shortlink in my Twitter tweets as well as in my Facebook shares. This url is automatically generated if you have the Stats plugin (now comes bundled with Jetpack) from WordPress installed. Every blog has their own unique url and so does every blog post in the world.
Since we need to use a URL Shortener with our tweets, why not this one? In addition to that, WordPress provides pretty extensive statistics for your blog with the Stats plugin.
The function to call the shortlink is ‘wp_get_shortlink’ and works for all the url shortener plugins which uses ‘get_shortlink’ filter to override the default shortlink (‘p=123′) property.
So, the full code to call the shortlink should be something like this:
<?php if (function_exists('wp_get_shortlink')) {
echo wp_get_shortlink(get_the_ID());
}
?>
If you want to use it as your twitter url shortener, you could use something like this within the loop. You need to have WordPress.com Stats plugin or JetPack (or any other url shortener plugin) installed and activated to use this.
<a href="http://twitter.com/share"
data-url="<?php if (function_exists('wp_get_shortlink')) { echo wp_get_shortlink(get_the_ID()); }?>"
data-counturl="<?php the_permalink(); ?>"
data-count="horizontal"
data-via="itsabhik"
data-related="itsabhik">Tweet</a>

If you want to reference the shortlink in your blog posts, you can add this within the loop:
<?php if (function_exists('wp_get_shortlink')) { ?>
<div><span>Shortlink:
<input type='text' value='<?php echo wp_get_shortlink(get_the_ID()); ?>' size='50' onclick='this.focus(); this.select();' />
</span></div>
<?php } ?>
That will add a box with the shortlink in it. The shortlink will be selected for easy copy and paste if clicked on the box. Thanks to Otto for the codes.






















Thankyou for this awesome tip Abhik.
luv this
I love the idea of it automatically generating. Thanks for the heads up on this Abhik. I will give wp.me a try.
- Robert
Thanks! Very helpful!