YOURLS (Your Own URL Shortener) is a URL shortener, like TinyURL, except it’s all GPL and you can run it on your own server, publicly or for your own use only. It was made by Lester Chan and myself. Learn more about YOURLS.
This plugin, YOURLS: WordPress to Twitter, is the bridge between YOURLS, Twitter and your blog: when you publish a post or a page, it will use your own YOURLS install, either hosted on the same webserver, or another server, to create a short URL for your post and send it to your Twitter account. The plugin also works with public popular services such as TinyURL, tr.im, is.gd or bit.ly.
Download
Extract and upload to your blog, preserving directory structure.
Enjoy.
Note: the plugin requires PHP 5 to run.
Features and configuration
Is a picture worth a thousand words? Here are 3000 words:
Plugin configuration:

Title little helper: count characters to help you keep under the tweetable 140 char limit:

From the Write screen, you can (re)generate short URLs and (re)promote your (old, for example) posts:

Template Tags for you theme
The plugin comes with two template tags:
wp_ozh_yourls_url()
Will echo a HTML link with short URL (will generate it on the fly if needed) for the current post.
Example output: <a href="http://ozh.in/j5" rel="nofollow alternate shorter" title="short URL">http://ozh.in/j5</a>
Suggested use: in the loop, in single.php, in page.php
wp_ozh_yourls_head_linkrel()
Will output a <link/> in <head> for the current post (see revcanonical.appspot.com and shorturl.appjet.net for more info)
Example output: <link rel="alternate short shorter shorturl" href="http://ozh.in/j5" />\n
Note that WordPress echoes this <link> out of the box so you mostly won’t need this one.
You can also use two other functions in your code and plugins:
wp_ozh_yourls_raw_url()
Will return (or echo if you pass true to it) the short URL, with no HTML tag or anything else. Just the raw URL.
wp_ozh_yourls_geturl( $id )
Will return (and generate on the fly if necessary) the short URL for post with id $id
Twitter message templates
As you can see in the main screenshot above, you can easily customize your tweets. What the screenshot doesn’t tell you is that there are many more tokens available:
- %U: the short url
- %T: the post’s title
- %A: the author’s display name
- %A{something}: the author’s ‘something’ as stored in the database. Example: %A{first_name}. See get_userdata(). Use this if for instance you’re running a multi author blog and each author has a Twitter contact information.
- %F{something}: custom post field ‘something’. See get_post_meta().
- %L: tags as plaintext and lowercase (space separated if more than one, up to 3 tags)
- %H: tags as hashtags and lowercase (space separated if more than one, up to 3 tags)
- %C: categories as plaintext and lowercase (space separated if more than one, up to 3 categories)
- %D: categories as hashtags and lowercase (space separated if more than one, up to 3 categories)
Remember, though: 140 characters is *short*. Since the title (token: %T) will be added last, it may really get shrunked if you had too many hashtags and stuff.
Easy custom keyword
If you want your post to have a custom short URL instead of the random/sequential generated one, when you write a new post add a new custom field to it (button: “Add Custom Field”) with name “yourls-keyword” and your custom keyword as a value.
Filters all over the place
If you’re a coder and want to interact with the plugin, there are a lot of filters for you to do so. Just read the source and look for what you need (and if you cannot find what you need because you’d like another filter somewhere else, please tell me!)
Feedback
Yeah. Go ahead.
Related posts
Shorter URL
Want to share or tweet this page? Please use this short URL: http://ozh.in/m7
Metastuff
269 Blablas
Pages: [27] 26 25 24 23 22 21 20 19 18 17 … 1 » Show All
Pages: [27] 26 25 24 23 22 21 20 19 18 17 … 1 » Show All
said, on 02/Sep/10 at 7:11 am # :
AGb » Normal behavior. Short URLs are created on the fly to be included in the <head> section, in place of the wp.me link
wrote, on 02/Sep/10 at 1:12 am # :
Great job Ozh! Thanks! One slight problem we’re having. The plugin is creating a short URL for blog posts that have previously been posted. It is not posting these to Twitter, just creating a short URL for these posts, some which were posted months ago. It would appear that these posts did not have a short URL previously, since their Original URLs are not duplicated in the database.
Disabled all plugins except YOURLS and it still creates a URL for old posts, approaching 400 since we upgraded yesterday. There has to be a trigger to this, but I have not isolate what it is. Any thoughts?
said, on 02/Sep/10 at 1:03 am # :
Jorgicio: Press the “Reset Consumer Key/Secret” button for the application you created @ http://twitter.com/apps for a new set of numbers while logged into you Twitter account. Copy these to YOURLS plugin. This should fix your issue.
replied, on 29/Aug/10 at 5:31 pm # :
Ozh:
I don’t think that may be a bad configuration… I put all my information correctly and I still have this error :/
said, on 27/Aug/10 at 3:42 pm # :
The plugin is very good working, but with the latest releases, I miss the re-twitter function for pages. How can I re-avtivate this?
Thank you
commented, on 26/Aug/10 at 8:52 am # :
Jorgicio » Bad plugin configuration
commented, on 25/Aug/10 at 11:22 pm # :
Hi. I’ve got the following problem when I try to connect my blog with Twitter.
Here it is:
Woah there!
This page is no longer valid. It looks like someone already used the token information you provided. Please return to the site that sent you to this page and try again … it was probably an honest mistake.
And I don’t know why it happens :/ And I don’t use the consumer keys in another plugin.
Thanks
thought, on 25/Aug/10 at 5:27 pm # :
Brad Zimmerman » Just pushed a plugin update that works with ‘yourls_keyword’ and ‘yourls-keyword’ to avoid confusion
said, on 25/Aug/10 at 4:56 pm # :
Thanks,
it did work using yourls_keyword, I would change you info above for others.