Create your own short URLs on WordPress

| May 19, 2009 | 2 Comments

short-cut-urlShort URLs are very popular among us especially who use Twitter. Many services (Like TinyURL, Bit.ly) are available to carry out this task. Although, they are enormously useful but using them has some disadvantages too :

1.  By using an outside service we are strengthening brand and driving users to the service, without gaining anything in return. It means useless promotion of something.

2.  There is always a risk of getting these URLs deleted, shifted or destination changed.

There are enough number of reasons to use short URLs of our own domain promoting our brand and those URLs will be stored on our server itself which makes their monitoring and tracking task easy. So, OutSpokenMedia suggested a trick to do it yourself.

To begin with and start creating own abbreviated short URL, you need a self hosted WordPress Blog and Link Shortcut WP Plugin.

Settings

Install and activate plugin conventionally and select 301 as redirecting option in plugin settings as it is SEO friendly and avoid duplicate content issue on search engines.

Character Length : Its the number of random characters to be used in short URL. Four is recommended whereas 8 (Eight) is default.
I would not ask to use Subdirectory option because it will unnecessarily increase URL length.

For Example : If I choose 4 then URL will become something like this http://blogsolute.com/hope = 26 which is less than 30 so acceptable on Twitter as it is the maximum limit, I think.

Use it for Tweet this button

You will need it to make this code modification in single.php file of your theme to get this short tweet URL below each post.

/* Grab Custom Short URL */
function grab_short_url() {
mysql_connect(”localhost”,”username”,”password”) or die(mysql_error());
mysql_select_DB(”database_name”);
$result = mysql_query(”SELECT * FROM wp_linkshortcut WHERE
url=’http://blogsolute.com” . $_SERVER["REQUEST_URI"] . “‘”);
if (mysql_num_rows($result)==0) {
$short_url = “http://blogsolute.com” . $_SERVER["REQUEST_URI"] . “”;
echo $short_url;
} else {
$short_url = “http://blogsolute.com/” . mysql_result($result,0,ident) . “”;
echo $short_url;
}
mysql_close();
}

Don’t forget to change the username, password and database name to be your own. Then, instead of calling <?php the_permalink() ?> in your “tweet this” link, change it to <?php grab_short_url() ?> and you’re all set.



You may also like:

  1. Tutorial on Applying Favicon to Your Blog on Blogger or WordPress
  2. Create and Split GIF images online
  3. 10 Things To Do after Installing WordPress
  4. Moving from Blogger to WordPress with Permalinks and Traffic
  5. Visionary, awesome Blogger Template and WordPress Theme

About the Author ()

Rohit Langde is editor-in-chief and owner of Blogsolute. He is Born-Geek and Technology Enthusiast. Being a blogger, he is also Mechanical Engineer who believes in simple Living. You can

Comments (2)

Trackback URL | Comments RSS Feed

  1. Samrat P says:

    This looks like a better option rather than using other services…

Leave a Reply