rel=”shortlink” Short URL Indicator and Its WordPress Support
As you know Short links are useful for microblogging, mobile applications as well as for applications where space or number of characters is a constraint. Many such famous services are available for shortening the URLs and are popularly known as URL shortening services. May be TinyURL is the most famous among them but also goo.gl from Google and t.co from Twitter, bit.ly etc are widely used.
But as you know many such services were short-lived and created ghost URLs where these shortened versions were not redirected to the actual URL as the URL shortening service become non functional. This is a major reason behind linkrot.
Linkrot is a phenomenon, were links on the web might become broken for several reasons. For example if the URL shortener becomes unreachable, the access to the final web resource will become impossible.
To overcome all these limitations rel=”shortlink” link attribute can be used to indicates that the hyperlink may be used for space constrained and/or manual entry. The author (Sam Johnston) released this work into the public domain and the rel=”shortlink” proposal solves the problem of linkrot.By adding rel=”shortlink” to a link in a page indicates that the hyperlink may be used for space constrained and/or manual entry.
How to Use rel=”shortlink” in HTML pages and HTTP header
You can use the rel=”shortlink” attribute of link tag in the HEAD section of an HTML page. See the example below.
<link rel="shortlink" href="http://yoursite.com/p123">
As part of HTTP header you can use s follows
Link: <http://yoursite.com/p123>; rel=shortlink
You can read the specification of shorlink
WordPress support for rel=”shortlink”
WordPress.com has its own URL shortening feature, wp.me. You can easily get shortlinks to your blog posts and pages using this service. You can see the “Get Shortlink button” next to the post/page Permalink when you create a new post or edit an existing post.
- “the_shortlink()” WordPress function can be used to display a “URL shortening” link for the current post.
- The function “wp_get_shortlink()” on the other hand outputs the complete shortlink for the post.
You can use “the_shortlink()” function as follows.
<?php the_shortlink( $text, $title, $before, $after ); ?>
were “text” is the link text to display, “title” is the tool-tip text displayed with the link and “before” and “after” are the HTML prefix and suffix added to the link.
Please note that by default, the short URL has a format of /?p=1234, and will only appear if pretty permalinks are enabled. See example below.
<link rel='shortlink' href='http://www.globinch.com/?p=5288' />
The ” wp_get_shortlink()” is used to get short Link to a post for use in PHP. You can make use of this in your template PHP code.
The usage is as follows.
<?php wp_get_shortlink($id, $context, allow_slugs); ?>
were “id” is the post or blog id, “context” is used to determine the id and context
and “allow_slugs” is to decide whether to allow post slugs in the shortlink.
There are many wordpress plugins available to make this process automatic. For example the Short Link WordPress plugin adds a rel=”shortlink” link to each page as well as the corresponding HTTP header.