Wordpress WP-Stats Shortlink Override

If you’re like me, you are addicted to stats. It’s probably not altogether a healthy addiction, but it’s there and we have to cope with it.

If you’re like me, you also dig shortcuts. Anything to make something easier, faster or even better, both–and it’s a lovely thing.

So if you’re like me, you probably are running WordPress 3.1+ and the WP-Stats plugin. Oh sure, I use other stat programs, but again–I’m addicted. It’s a neat, handy, quick way of getting stats and even better, it’s free. And if you use shortlinks, i.e. this post can be both “http://www.needcoffee.com/2011/04/16/wp-stats-shortlink-override/” and “http://needcoffee.com/?p=19837” then the fact you can snag the shortlink from the admin bar when you’re on a single page of the site…that is awesome.

However.

The WP-Stats plugin…and I’m not exactly sure why this was done and even less sure why it’s not an option to turn it off…overrides what would be ” ” and makes it “wp.me/something.” Being a vain person and liking my site name out there, I don’t want wp.me and am perfectly happen with “needcoffee.com.”

What to do?

Carve the offending bit of code out of the stats plugin.

Here’s what you do: first, open the stats.php file in a text editor. Please do the smart thing and make a backup copy of the file. Always back up a file before you start performing surgery on it.

Find the following code, which in my copy of the file starts at line 1227:

if ( stats_get_option('wp_me') ) {
	if ( ! function_exists('wp_get_shortlink') ) {
		// Register these only for WP < 3.0.
		add_action('wp_head', 'wpme_shortlink_wp_head');
		add_action('wp', 'wpme_shortlink_header');
		add_filter( 'get_sample_permalink_html', 'wpme_get_shortlink_html', 10, 2 );
	} else {
		// Register a shortlink handler for WP >= 3.0.
		add_filter('get_shortlink', 'wpme_get_shortlink_handler', 10, 4);
	}
}

Delete the code. Save the file. Upload the file. Bang. Your shortlinks are yours once more.

Please note: I am not a coder, so this is probably a very ugly way to get this done. But it is effective. Enjoy.