Shortlink trick
For you people who do your own theme work:
<?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 } ?>
Basically that adds a little Shortlink: input box with the shortlink in it. Click the box, and the shortlink becomes selected for easy copy and paste.
It’ll also work with any shortlink plugin that uses the “get_shortlink” filter to override the shortlink properly (like WordPress.com Stats).
Put it somewhere in The Loop or on the Single Post pages or what have you.
Shortlink:
The problem with get_shortlink() is that if you want to define it the way Stats does, you have to make your plugin load before Stats does. I really dislike the whole pluggable way of doing things WP uses.
Oh and BTW yay for Ottpress, hopefully that will make you write more about WP
Pluggable functions can be a bit tricky sometimes. However, presumably, any given user would be only activating one shortlink plugin at a time, and thus, no conflict.
So, my beef there would be that the wp.me shortlink stuff should be in a separate plugin, not in stats. However, they have pretty well tied it to the stats, unfortunately.
Still, if you want to force your plugin to load before stats does, it’s not hard to do. Get the active_plugins option, manipulate the array to put your plugin ahead of stats, then save the option again. Best to do this on the “activated_plugin” action hook.
Or just use a plugin name before “S” in the alphabet (that option gets sorted when a plugin is activated).
Shortlink trick » Otto on WordPress…
この記事は以下サイトで紹介されています。 WordPressハッカーズ…
[...] One can filter the_shortlink() function to display custom created shortlinks using pre_get_shortlink() and get_shortlink() hooks. More Information by WPEngineer and OttoPress. [...]
[...] content, using straight not smart quotes, deny comment posting to no referrer requests, and more.Shortlink trick – Otto on WordPress – Many are adding auto-shortlinks or tinyurls to their blog posts for easy tweeting and [...]
I assume the code needs to be updated to reference wp_get_shortlink()?
Yep. I wrote this when the core code was still in beta.