Shortlinks with WordPress 3.0

There will be a new function in the coming 3.0 version, which will create a shortlink to a post. At default it will be in the header of your frontend.

A shortlink would always be with ?p= syntax and the ID of the post.
<link rel='shortlink' href='' />

To use the shortlink in your theme, you can use a template tag with 4 parameters.

 * @param string $text Optional The link text or HTML to be displayed.  Defaults to 'This is the short link.'
 * @param string $title Optional The tooltip for the link.  Must be sanitized.  Defaults to the sanitized post title.
 * @param string $before Optional HTML to display before the link.
 * @param string $before Optional HTML to display after the link.
the_shortlink($text = '', $title = '', $before = '', $after = '')

Here an example how you can use it in your theme:

if ( function_exists('the_shortlink') ) the_shortlink( __('Shortlink'), __('kurze URL zu diesem Beitrag nutzen'), ' · ' );

The function wp_get_shortlink() is in use in this case. You should use this function if you don’t want to have it displayed (echo).

The link in the head of the frontend is created via a hook and can only get disabled. The integration will be standard in WordPress 3.0:

add_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );

To deactivate the syntax in the head of your template you can put the following code in your functions.php.

remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );

If you like to adjust the shortlink to your liking, you can use several filter hooks.
pre_get_shortlink // Allow plugins to short-circuit this function
get_shortlink // Filter the output

Comments are closed.


  1. Konstantin

    Yeah, shortlinks are good, though some people like custom domains and alpha-numeric short links 😉 Hurray for 3.0!

  2. Nicolas

    Is this going to replace the WP short link that you can get already with WP 2.9 or do you have to explicitly add this code to your theme for it to work with your own domain?

  3. Frank

    @Nicolas: i dont find this functions in WP 2.9, first in WP 3.0 – please see the source.

  4. Tomáš Kapler

    not much usefull, ID was anyway always visible in URL. I would much more prefer some way to interlink to other posts/pages, which would be connected to ID, but the URL would change to real URL based on my URL settings. So e.g. i want to link article Hello World, id 1 with slug, so that i would not have to write after clicking Anchor button the url and have to repair it when changing URL, but to have some easy way how to select Hello World article from e.g. dropdown, it would add something like [link:1] which would be replaced to or or whatever i have in my settings.

  5. Jeph

    I see it in 2.92 and it generates a link with some alphanumeric combo after the slash.

  6. eavasi™

    Short linck is what sorely lacking in the old WordPress. Good luck for us with WordPress 3

  7. dNoxs

    I’m still waiting wp 3.0 fnal.. thank for tips wp 3.0

  8. Tammy Hart

    What is the purpose or use for this? This is a great explanation on how to implement it, but i’m just not understanding what it is needed for.

  9. Aizat Faiz

    @Tammy Hart, this is useful because shortlinks translate to permalinks. Shortened links are useful if you want to give short URLs to a friend, or physical media. Plus shortlinks never change, while permalinks may (by changing a post slug). So if you link things via shortlinks, your site, should theoretically always be functional.

  10. eavasi

    Its the function which lacked in the older versions!!! (

  11. agenerousdesigner

    Why is this a new feature? ?p=[post’s id here] always works with or without turning on the permalink functions.
    I don’t get it. :S

  12. CJEllison

    I’ve been searching around to perfect a plugin I need to make for a client. This info put the icing on the cake.

    The “wp_get_shortlink()” tag is exactly what I needed, and I couldn’t find it anywhere online until I found it here.

  13. SK

    How can we get the shortlink value?

    This only lets us return it as a formatted link.

    What if I want to show an text box with the URL in it so it is easy to copy?

4 pingbacks

  1. Links curtos com o Wordpress 3.0 | Wordpress Love - Themes, Plugins e tudo para Wordpress, em Português
  2. A Standard to Specify a Canonical Short Link
  3. Tips & Guider till WordPress 3
  4. 10 of the Best Tutorials to Get You Up to Speed With WordPress 3.0 - WordPress MU and BuddyPress plugins, themes, support, tips and how to's