shortlinks

Before pretty permalinks were the norm, we used shortlinks, which are default links created by WordPress to link to your blog posts. For example, before customizing your permalinks structure, the link to the first post on your blog is:

http://yoursite.com/?post=1

instead of

http://yoursite.com/hello-world

The problem with that is blogs tend to have many entries you can’t keep track of. For example, pretend you wrote a post a long time ago titled, “Goodbye World.” What is the ID number or link for that post now? Is it 498 or 500? You don’t have time to remember all 500 posts and neither do I.

But, once you’ve customized your permalinks to use post titles instead of post ID numbers, the shortlinks get hidden and not everyone knows how to get them back or look for them. Even for people who knows how, it’s time consuming if more than one shortlink is needed, which is why WordPress 3.0 is making it easier to grab shorlinks by adding a Get Shorlink button.

While permalinks that use titles instead of ID numbers are easy to easy to remember and good for search engines, they’re long and some are temporary. For example, what if you needed to paste a link into a Twitter post (which is limited to 140 characters), would you use

http://yoursite.com/?post=2

or

http:/yoursite.com/the-best-post-ive-ever-written

?

The second disadvantage of the longer link is that it could change if you ever needed to change the title of that post. Lets pretend again that you’ve published the Twitter post with the longer link then decides to change the title and URL address of that post two days later to something like, “The Best Post I’ve Ever Written… Yet”. WordPress will update your blog for you, but will not update Twitter so everyone who clicks on the link you previously published on Twitter after the title and URL change will end up at a blank page.

On the flip side, if you had instead on Twitter linked to the shortlink, it doesn’t matter how many times you change the title or URL address, it stays the same. Anyone clicking on the link on Twitter before or after the URL change would be sent to the same page.

How to Enable Short Links

The good news is if you’ve never customized your permalinks structure then you ARE currently using shortlinks. Ta da! If you’ve never customized permalinks for your blog then your permalinks page should look like this:

And when you write or edit a post, the Get Shortlink button should not be present similar to this image:

Click on Get Shortlink button to grab the shortlink,

How to Display Shortlinks on Your Blog

Maybe your readers have a habit of linking to your blog posts on their Twitter accounts and you’d like to make it easier to for them to do so by giving easy access to the shortlinks instead of forcing them to use URL shortening services like TinyURL and Bit.ly. Well, here’s how:

– Open up your theme’s folder and find the index.php and single.php template files.
– Find The Loop in both files and paste the following line within the loop:

<?php the_shortlink('Shortlink', '', '', ''); ?>

– Save both files and upload it to your web hosting server to see the change made to your blog.

Explanation for the line of code above:

– I’m starting a set of PHP codes.

– Let’s use the_shortlink() function of WordPress to display shortlinks on my blog.

– Within the_shortlink(), there are four options for me to customize the actual display of shortlinks represented by four sets of single quotes.

– First of all, in the first option I want all shortlink display titles, regardless of the actual title of the post or ID number, to be Shortlink. Although it could be anything like say… Peanut, in which all posts would have a Peanut title link, linking to the actual shortlink URL.

– The second, third, and fourth options for customizing the shortlink display are empty because I don’t need them. But if I did:

  • Second option is for link title, which is different display title. The link title is hidden until you hover over the link you want to click on, then it pops up for you to read. For example, if I use Something Random in the second set of single quotes, when you hover over Shortlink, it would pop up “Something Random,” instead of the actual title of the blog post.
  • Third option is for placing anything before the actual link display title.
  • Fourth option or set of single quotes is for placing anything after the link display title.

Here’s an example of all customizable options filled out:

<?php the_shortlink('Peanut', 'Something Random', 'before', 'after'); ?>

As you can see from the screenshot above, anything you place in in the third and fourth sets of single quotes will be placed directly before and after the actual display title, without any additional spacing if you don’t include the spacing. However, the third and fourth customizable options are often used for adding codes for styling, which would not need additional spacing for it to look like it makes sense.

Going back to the first and second options, see how my display title is Peanut and link title is Something Random? It’d be weird if you use that combination for all posts because they wouldn’t make sense. Especially Something Random, different shortlinks to different posts have different titles, they don’t all have Something Random as the title so leave the second option empty. When you leave it empty, WordPress defaults to using the post titles in the place of link titles.

Shortlinks Resources