Creating Short Post Urls Within WordPress

Creating Short Post Urls Within WordPress
November 27, 20090 Comments

With the popularity of Twitter, short urls are almost a necessity these days trying to maintain the limit of 140 characters. Using a short url as default in WordPress tends to hurt your search engine optimization and looks just so, well, "default". Here are a couple of ways you can easily and automatically create a short url for use in WordPress without a plug-in.

I'll start out by saying if you are using the WordPress hosted version, the short url is automatically created thanks to http://WP.me, a url shortening service provided by Automattic, the guys who made WordPress.

If you are hosting your own version of WordPress and have a non-lengthy domain name, you have some options. Yes, you could easily use a plug-in that does it for you, but at least for me it's much more gratifying to open the text editor and get my hands dirty.

Using Default Settings To Your Advantage

On a fresh install of WordPress, the settings in your admin panel are set to display your post id after your domain address for the permalink like the image below.

Default permalinks in the admin section of WordPress

Default permalinks in the admin section of WordPress

If you copy and paste a permalink with a post id into your browser address bar and have changed your settings to one of the other styles of permalinks with mod-rewrite enabled, WordPress auto-magically redirects to the longer post url based on the permalink settings you are using.

Making use of these built in features is the easiest way to create and share short post permalinks. It also reduces server load, page loading time since there are less outgoing requests to process before loading the shortened url and still uses any stats tracking you have installed in WordPress so there are no external applications needed.

Implementation and Usage

Using these short urls within WordPress is very simple. All you have to do is call the post id somewhere in the loop with your domain name like this: http://www.vagrantradio.com/?p=<? php the_ID(); ? >. You can even get creative and create a link that includes your post title as well as "Currently Reading" for easy tweets. Below is an example of this link in action and the code used to create it.

<a href="http://twitter.com/home?status=Currently Reading <?php the_title(); ?>
: http://www.vagrantradio.com/?p=<?php the_ID(); ?>" title="Tweet this">Tweet This Post</a>

Try Me: Tweet This Post

An example of a generated tweet from a link in WordPress

An example of a generated tweet from a link in WordPress

And there you have it, A simple easy way to create shortened urls in WordPress that requires no external services or scripts and still uses any internal stats tracking you have installed. I'm sure there might be a few caveats to this technique, but I can't think of any off the top of my head. Any thoughts or suggestions on this method?

Author: Jason

Hi, I'm Jason. A front end developer from Grand Rapids, Michigan, and founder of VagrantRadio. I enjoy working with Css, jQuery, Php, learning new techniques in Photoshop and you should follow me on Twitter or Snipplr.

Mojo Themes
Scroll to top