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>

wp.me url shortener Use WP.ME As URL Shortener
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.

Hi, I am Abhik and this is my blog ItsAbhik.
I write about Search Engine Optimization (SEO) and Internet Marketing here in this blog and provide tips on how you can make money online. More about me..

You are welcome to write a Guest Post on this blog and share your stories with us.
Follow me on:  TwitterFacebook and Google+

Subscribe for FREE and EXCLUSIVE Stories

4 Comments

  1. Piyush

    Thankyou for this awesome tip Abhik.

  2. shoyombo olayinka

    luv this

  3. I love the idea of it automatically generating. Thanks for the heads up on this Abhik. I will give wp.me a try.

    - Robert

Leave a Reply

Copyright © 2006 - 2012 ItsAbhik Media. All rights reserved.
ItsAbhik Powered By WordPress | CDN by MaxCDN | Hosted by Hostgator