YOURL’s WordPress Plugin Update for 3.0

UPDATE: Thanks to Ozh’s Comments I have updated the post below. It sounds like the plugin will be updated for WP 3.0. However, it will then stop working with WP 2.9 and below. I am leaving this page up for those of you who wish to use an older version of WP but would still recommend updating to a newer release when one becomes available.

I’ve been using YOURLS to host my own shortlink site at for quite some time. I recently found the YOURL’s WordPress to Twitter Plugin. This plugin is great however the, get_shortlink function added to WP 3.0 as well as the latest version of Stats plugin caused some small usability issues. Such as the “Get Shortlink” button showing up twice.

My solution? Make it so when you click on the “Get Shortlink” button it gets the YOURLS shorlink instead of the one. This required the following changes that I’m hoping OZH will adopt or modify.

Remove the following from inc/options.php (Lines 427-428)

$('#edit-slug-box').append('<span id="<span class=">yourls-shorturl-button</span>"><a onclick="prompt(\'Short URL:\', \'<?php echo $shorturl; ?>\'); return false;" href="#">Get Short URL</a>');
 $('#yourls-shorturl-button a').css('border-color','#bbf');

Next add the following functions to either inc/core.php or plugin.php

//the following two functions are from Stats Plugin by Andy Skelton Thanks Andy
//shortlink url for WP <= 2.9
function wp_ozh_yourls_get_shortlink_html($html) {
 $url = wp_ozh_yourls_geturl($id);
 $html .= '<input id="YOURLS-shorturl" type="hidden" value="' . $url . '" /><a onclick="prompt('URL:', jQuery(\'#YOURLS-shorturl\').val()); return false;" href="#">' . __('Get Shortlink') . '</a>';
 return $html;


The final step is to modify the plugin.php file to change the renamed wpme functions and update for WP 3.0

// WP 2.9/3.0 & play nice together
add_action('plugins_loaded', 'wp_ozh_yourls_wpme' );
function wp_ozh_yourls_wpme() {
 if( ! function_exists('wp_get_shortlink') ) {
 // Remove these only for WP < 3.0.
 remove_action('wp_head', 'wpme_shortlink_wp_head');
 remove_action('wp', 'wpme_shortlink_header');
 //Add shortlink URL html
 add_filter( 'get_sample_permalink_html', 'wp_ozh_yourls_get_shortlink_html');
 } else {
 // Add a shortlink handler for WP >= 3.0.
 add_filter( 'get_shortlink', 'wp_ozh_yourls_raw_url');

That should do the trick and be backwards compatible!

3 thoughts on “YOURL’s WordPress Plugin Update for 3.0

  1. There’s even simpler, I’ll update the plugin this way:
    – step 1 OK
    – step 2 and 3 not needed, just replace with add_filter( ‘pre_get_shortlink’, ‘wp_ozh_yourls_raw_url’ ); and remove deprecated functions from the plugin

    (I don’t care about backward compat 🙂

  2. (Actually it’s better to hook into ‘get_shortlink’ as it deals with the context, ie single or front page etc)

    1. Thanks Ozh,

      I’m still relitivly new to WordPress and was tired of seeing two shortlink buttons in 2.9 and wanted to “fix” the shortlink button for 3.0. Thanks for your input!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.