On: 2009/06/25
Shorter URL for this page: http://ozh.in/m7

yourls-logoYOURLS (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 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.

The latest version of the plugin does not support Twitter any longer. I have not enough free time to maintain that part, due to the regular changes from Twitter on their authentication process. If you want to auto tweet your posts, use a plugin for that.
This plugin is not maintained any longer. It's still working probably fine (here on this blog for instance) but I'm not investing any more time on it. No support or anything.

Download

Download the plugin : yourls-wordpress-to-twitter.zip
Extract and upload to your blog, preserving directory structure.
Enjoy.

Note: the plugin requires PHP 5 to run.

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

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!)

Shorter URL

Want to share or tweet this page? Please use this short URL: http://ozh.in/m7

Metastuff

This page "YOURLS WordPress (a Short URL Plugin)" was posted on 25/06/2009 at 10:15 pm
Watch this discussion : Comments RSS 2.0.

472 Blablas

  1. mark beekman says:

    here's what i found:

  2. mark beekman says:

    Appears code was stripped from comment:

    response action='yourls-promote_0′ object id='0′ position='1′

  3. Wolfgang says:

    There is an error in the new version 1.2. It sends out a php-warning after activating and after a click on the WP-dashboard:

    Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'wp_ozh_yourls_add_dashboard_widgets' was given in /**deleted****/wp-includes/plugin.php on line 339

    Greetings

  4. Ozh says:

    Wolfgang » oooops, I forgot to remove this test before committing :P Thanks for the head up, it's fixed in 1.2.1

  5. Wolfgang says:

    Thank you :-)

  6. mark beekman says:

    Works great now. Thanks for the fix.

  7. joshnunn says:

    I just can't get wp_ozh_yourls_raw_url() to work for me – I get no output from it.

    This is what I have in my theme:

    1. &lt;a href=&quot;http://twitter.com/home?status= - " title="share on twitter"&gt;Share on Twitter</a>
  8. Sujit says:

    Hi there Ozh !!!
    I saw u added something about ping.fm in the plugin.
    Thanks for tht.

    Hope it would be functioning soon… ;)

  9. Ozh says:

    Sujit » I added the code, in theory it works. Now just waiting for those retards from ping.fm (yeah, I don't like this site and it's slow as hell) to approve my application key I requested more than 10 days ago.

  10. […] that it offered per-user stats but global stats will work for now. The best part of YOURLS is a WordPress plugin from the same author. The plugin comes dangerously close to giving me the workflow I described in […]

  11. Thanks for an awesome plugin and script. Have been busy setting it up to working with all of our various domains and it all appears to be working smoothly.

    Thanks again.

    Paul

  12. Garret says:

    Sorry, was not clear or complete. I am using Yourls. The plugin is not creating a link there it doesn't look like no posting a tweet. How can I debug this?

    Better I hope.

    Garret

  13. Ozh says:

    Garret » Use firebug and check the return of the Ajax call

  14. Garret says:

    Ozh,

    Got it thanks, I think primaryly user related. Thanks again!

    Garret

  15. Garret says:

    Ozh,

    I do have some questions about how the search engines relate to this shortener. Both Google and Bing and indexing now, Some of the other shorteners are really starting to take this into consideration. Are you guys putting some thought into this, and are you doing anything related to this?

    Thanks
    Garret

  16. Ozh says:

    Garret » I don't see how indexing and URL shortener relate…

  17. Garret says:

    I apologize, I have gotten very little sleep the last few days.
    The search engines are indexing Twitter much more these days. I know that some of the url shorteners are talking about incorporating 301 redirects. I would like to know if anything, what you are looking at enabling some functionality that enables good seo.

    Thanks for your patience man
    /me so friggen tired

  18. Ozh says:

    Garret » As far as I know *all* URL shorteners are using 301. I wouldn't use one that does 302. And of course YOURLS is using 301 too, as you can see easily if you look into the source.

  19. Sujit says:

    >>OZH
    Hi there… I agree !!!
    almost all the developers i know who've tried something with ping.fm have complained about their application key being accepted after a hell lot time.

    Lets cross our fingers and wait for those useless people to clear out things. :(

  20. Travis says:

    I'd love to see another function added to the plugin that outputs a plain text url not wrapped in an href.

    For now, I modified your plugin to do just that, creating a new function called wp_ozh_yourls_plain_url(), which only prints "$short".

    This is handy for printing the url in an input form field that people can easily click on and copy (a la YouTube's embed code form).

    Thanks. Ozh.

  21. Ozh says:

    Travis » That's what wp_ozh_yourls_raw_url() is for (not sure I updated the doc about this one)

  22. Travis says:

    I guess I should have scrolled down a little further :) My bad. Thanks, Ozh!

  23. George says:

    This plugin broke my site! Wouldn't let me edit posts, spent ages debugging and it turned out to be this! Deleted immediately!

  24. joshnunn says:

    @George – there's a known issue with this plugin when used with twitter tools that sounds like the problem you're having. Ozh may have fixed that issue since first reported, but if he hasn't I'm sure he's on top of it.

  25. Jamie says:

    George, please be fair, This plugin did not break your site, If it did it would break all sites, It is most likely tha the problem was caused by your unique combination of plugins rather tha just this one. See the post above for the best place to start!

  26. Ozh says:

    joshnunn & George » as far as I know the issue with Twitter Tools has been fixed. And I can't do anything else valuable with dumb feedback like "it broke my site!!!".

  27. Scott says:

    First of all – thanks for such a brilliant plugin and service (YOURLS). I set up my own service via thmm.eu, and it works like a dream for stuff published on my slightly longer-named site http://www.themusicmagazine.co.uk.

    The problem I'm having is that the plugin isn't actually publishing a URL to my Twitter feed (@tmmfeed – a new one set up just for this). I have to click "retweet" up to five times for it to publish anything, and it has never worked by just clicking publish on WordPress – despite the plugin options being ticked. Just wondering if it's anything that you've come across that I can apply a fix for, or if there's anything I can try.

    Otherwise, a brilliant job!

  28. Ozh says:

    Scott » If it works "sometimes" after you click retweet, then there must be something funky on your side. Is there any error when you tweet and it doesn't work, or does it just fail silently?

  29. Scott says:

    Thanks for the reply!

    It just fails silently. It claims to have been a success, however nothing appears on the Twitter feed. I wouldn't even know where to start looking for a problem!

  30. kenduret says:

    Great plugin and service… now if I could only get it to work. All is well until I click on the short url at twitter.

    The short url is not re-directing to the post. Instead I go to the short url domain and get this on the screen:

    string(78) "http://mydomain.com/where-i-should-be-redirected-to/"

    Any ideas?

  31. Ozh says:

    kenduret » Yes. Use latest version.

  32. kenduret says:

    Doh!- No wonder you're famous and I'm not!

    Working beautifully.

  33. Rodney says:

    I think I found a bug:

    If you're using a remote/private yourls install and you enter your username/password wrong on the plugin setup page. Shorten urls for pages turned on.

    Then, if you go to edit a wordpress page, it tries to generate a shorturl for that page. Since the username/password was incorrect, it shows "invalid username/password" for the yourls_shorturl value.

    The problem is that there seems to be no way to fix this error and regenerate a shorturl for the page if you fix the username/password in the plugin settings.

    I tried deleting the custom field, but it doesn't seem to regenerate the short url if I go back and edit the page.

  34. Ozh says:

    Rodney » The problem is that you're changing the login/pwd in WP's options, but the old values are still cached until next cache refresh

  35. Rodney says:

    Ahh, cache. I didn't think of that. I just went back to edit the page and Viola, it worked just fine. Thanks (and thanks for the great script)!

  36. Rodney says:

    I'm trying to use yours>twitter with the wpgreetbox plugin so that it includes the shorturl generated by yourls when it allows people to share a post via twitter.

    In the last template tag example above, can you tell me how to pass the echo parameter to the tag?

    I read the codex page here:
    http://codex.wordpress.org/Template_Tags/How_to_Pass_Tag_Parameters

    And tried:
    twitthis.com/twit?url=

    And:
    twitthis.com/twit?url=

    But neither seemed to work.

  37. Ozh says:

    Rodney » Sorry I don't know the wpgreetbox plugin. You should contact the author of this plugin and ask if there's a way to pass a parameter. Even better, ask him to add a hook so that other plugins or themes can modify what his plugin display.

  38. mark beekman says:

    Ozh, any idea when you'll be releasing the next version? The new stats functionality, graphs and demo page look amazing.

    Thanks for the great work on this.

  39. Ozh says:

    mark beekman » Everything is done, mostly, I just want to make sure the installer / upgrader is robust enough. I'm waiting for some feedback from beta testers. Hopefully this week-end, or maybe next week.

  40. Garret says:

    If you need any more beta testers I have some bandwidth for that right now.

    Garret

  41. Ozh says:

    Garret » it's not really about bandwidth, it's more about being able to provide consistent feedback :) Thanks for the suggestion anyway, I'm waiting for the first batch of testers' feedback to check whether I was really off or not, and then I'll advise.

  42. Garret says:

    Ozh, I meant bandwidth as in bandwidth = personal time. But I understand, just let me know if I can help.

    Garret

  43. Andrew Merskin says:

    I'm also getting the blasted "Bleh .. can't post to Twitter .. it's 'down'" stuff. Twitter login is correct, checked three times. Running WP2.8.4 and YOURLS 1.3.1.

    Here is my XML response from Firebug:

    Any help would be greatly appreciated. I have been trying to get my posts to Twitter for weeks without any luck with other plugins, and this one as well. I was using Tweet Suite before this and suddenly TinyURL stopped working… post titles went to Twitter without links or anything.

    Thanks!
    Andy

  44. Sebi says:

    Hello Ozh ;)
    Your plugin is really cool stuff. But I have one big wish: Is it possible to implement a Dashboard Widget which allows me to post manually to my Twitter-account. I often want to publish a link to other interesting sites and it would be very helpful if I could do this from my Dashboard and with my own shortening-url.

  45. Ozh says:

    Sebi » At the moment the best way to do so is shorten a link with the bookmarklet and use the Quick Share box. Not sure I'll implement this in the plugin because that's a totally different concept (twitter client vs bridge between YOURLS and the blog). Will think about it though.

  46. Sebi says:

    Well I think this Plugin is already a Twitter Client due to its ability to post to Twitter.
    The funcionality I suggested would enhance the helpfulness for every blogger because it allows to not only use Twitter as a timeline of the blogs content, but to really use Twitter as an extension to the wordpress-blog. So one could easily use Twitter for content-related short messages with the same specific Link-URL-Synthax as it is used by tweeting the blogs content. So it's about corporate identity ;) Think about it =)

  47. Seth Long says:

    Ozh – Love the plugin and YOURLS. We run WPMU and it would be extremely useful to us if the plugin supported MU. With the current version, we need to provide setup instructions for our users, most of whom aren't technically-minded. I would like to pre-set and hide the short URL service info, and just pre-set the rest of the preferences, to avoid user confusion and to increase usage of the plugin.

    Thanks for considering this. I'm looking forward to v1.4.

  48. Andy says:

    Have you considered some implementation of OAuth for this plugin?

    I know the reason I use my own shortening is that people can trust me and my links. However, since so many spambots on Twitter have posts that state "sent from API" people get a little nervous about posts that include that.

    It would be great if the post said "sent from Yourls" or something like that instead. I don't know what is involved to implement this, but I think it would help immensely.

    Thanks for your time!

  49. Ozh says:

    Andy » I have considered and won't. Please see issue 64: http://code.google.com/p/yourls/issues/detail?id=64

  50. Rose says:

    This is not working for me. I enabled it. looks fine, added login and api keys but still nothing on twitter. And other plugins aren't working either.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
Gravatars: Curious about the little images next to each commenter's name ? Go to Gravatar and sign for a free account
Spam: Various spam plugins may be activated. I'll put pins in a Voodoo doll if you spam me.