Create your own short URLs on WordPress
Short 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 https://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=’https://blogsolute.com” . $_SERVER[“REQUEST_URI”] . “‘”);
if (mysql_num_rows($result)==0) {
$short_url = “https://blogsolute.com” . $_SERVER[“REQUEST_URI”] . “”;
echo $short_url;
} else {
$short_url = “https://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.