Note:
WP 3.0 changed all this. It'll support shortlinks natively, with plugins doing the heavy lifting.
Default shortlinks will be of the
http://example.com/?p=ID format.
Plugins can override this to make their own shortlink output.
Functions of use:
the_shortlink($text = '', $title = '', $before = '', $after = '') - Loop function, outputs the shortlink in the form of an a href link.
wp_get_shortlink($id = 0, $context = 'post', $allow_slugs = true) - Returns the shortlink. Can optionally return the shortlink for an item defined by the item id and the context. Allow slugs is for use by plugins only.
wp_shortlink_wp_head() - inserts link tags into the html head.
wp_shortlink_header() - inserts link tags into the http header.
These can be disabled like so, if desired (shouldn't be necessary):
remove_action( 'template_redirect', 'wp_shortlink_header', 11, 0 );
remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );
A plugin has two filters it can use to override the shortlink:
pre_get_shortlink - Happens before default shortlink generation. If this filter gets anything returned to it, then the default stuff gets skipped. Probably should be used by most shortlink plugins.
get_shortlink - Happens after default shortlink generation. Only should be used to modify default shortlinks.
Using either of those to modify the shortlink will cause your modification to show up everywhere the shortlink functions are used.
Example usage:
PHP Code:
<?php if (function_exists('wp_get_shortlink')) { ?>
<div><span class="post-shortlink">Shortlink:
<input type='text' value='<?php echo wp_get_shortlink(get_the_ID()); ?>' onclick='this.focus(); this.select();' />
</span></div>
<?php } ?>
Shows an input box with the shortlink in it. Clicking the box selects the shortlink for copy/paste.