Create your own short URLs on WordPress

short-cut-urlShort URLs are very popular among us especially who use Twitter. Many services (Like TinyURL, 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.


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 = 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());
$result = mysql_query(”SELECT * FROM wp_linkshortcut WHERE
url=’” . $_SERVER[“REQUEST_URI”] . “‘”);
if (mysql_num_rows($result)==0) {
$short_url = “” . $_SERVER[“REQUEST_URI”] . “”;
echo $short_url;
} else {
$short_url = “” . mysql_result($result,0,ident) . “”;
echo $short_url;

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.


About the Author

Rohit Langde is Founder and Editor-in-chief of Blogsolute. Tech Blogger by Passion & Profession | Mechanical Engineer by Qualification | Introverted Geek by Choice

2 Enlightened Replies

Trackback  •  Comments RSS

  1. Samrat P says:

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

Post a Reply

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