Make Your Own Short URLs in WordPress

Your website URL is better than someone elses.
Quit Using URL Shortener Services.

Why Not Just Use Some URL Shortening Service?

If you’re arriving at this article directly, head back to part one to read about why to make your own short urls.

In a nutshell, I’ll summarize the whole article by saying that asking people to trust a cloaked link is not something you should ask anyone to do.

Methods of Shortening URLs

There are several different ways to handle URL shortening, and I’m going to list as many as I can think of here.

For WordPress Self-Install Users

If you use WordPress, you have it fairly easy. Remember back to the day you installed WordPress and you had those ‘ugly’ urls that were just your domain and a number? Did you realize those URLs still work? They do, nowadays they just redirect to whatever nice readable format you changed your permalinks to be (which I’m sure you did, riiighhht?).

In fact, you users have two options. Use a plugin or add the code yourself.

The Plugin Option:

A good one is la petite url which uses your own domain to make your short url. When you save a post it shows the short url in the sidebar of your administrative interface. You can then drag this into your post. If you’re comfortable editing your theme files, you can add a bit of code to your single and page files so that it shows up automatically. It’s available on the WordPress Plugin repository here: la petite url

The Template Option:

Just head into your template editor and add a link to your short url into your Single and Page files. This should work fine for most templates, although a highly customized one may have different page types that you will need to add this to separately.

For a simple text display of the link, add the following code where ever you want in your theme file:
<span>Short URL: <?php get_bloginfo('url'); ?>/?<?php the_ID(); ?></span>

If you want to use a textbox type of display where people can easily select the text, try a variation on something like this:
<span>Short URL: <input type="text" value="<?php get_bloginfo('url'); ?>/?<?php the_ID(); ?>" style="width:50%;"/></span>

For WordPress.com Users

As you know, you can’t install plugins or edit template code if you have a WordPress.com blog. You can, however, still make your links a bit shorter than they are now because your posts still have a numeric version available.

You would need to add (manually) text at the bottom of your posts to provide the short link to your visitors. The link would look like this:

http://yoursite.wordpress.com/?POSTID

But how do you find the POST ID for a WordPress.com blog? It’s not hard at all. I’m going to provide two screenshots to show you where to find it.

From the posts list screen:

Finding Post ID From List Screen.
Finding Post ID From List Screen.

From the editing screen:

Find Post ID While Editing.
Find Post ID While Editing.

Remember, for WordPress.com people, this means adding that at the bottom of your posts when you make them.

The series so far:

Part 1: I Don’t Trust Short URL’s
Part 2: This article
Part 3: Make Your Own Short URLs in EE, MT, Joomla and Drupal
Part 4: Make Your Own Short URLs With Domains or Software

6 Replies to “Make Your Own Short URLs in WordPress”

  1. I was searching around online the other day for some info regarding wordpress.com short urls, and I found your site. I tried your method, but couldn’t quite get it to work, so I started playing around on my own, and here’s what I found:

    http://elisfanclub.com/built

    (that URL is just one example of what I found)

  2. This is great. Thanks for sharing this information and for everyone that commented on their experience. If I ever get around to tweeting more, I’ll definitely give this a try.

  3. Just letting you guys know that version 2 of la petite url includes a sidebar widget, so you won’t have to write a single line of code to get your short URLs to show up on page.

  4. You are so cool! I don’t suppose I’ve read through something like that before. So wonderful to find another person with a few unique thoughts on this issue. Seriously.. thank you for starting this up. This web site is one thing that is needed on the web, someone with a bit of originality!

Comments are closed.