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. Aryan says:

    /** Private means protected with login/pass as defined below. Set to false for public usage. */
    define('YOURLS_PRIVATE', false);

    Look at this ….

    if i set it to true no one can see stats of its shorten url…. and if it is false than anyone can access the admin panel
    or if i change the path of my admin folder

    my yourls to twitter plugin stops working

    Need Your help in this badly

  2. Ozh says:

    Aryan » http://yourls.org/#Config see Optional settings

  3. Aryan says:

    you are not getting me … i want that people can see stat and able to use my website shortening service with yourls plugin but on the other hand admin must be protected

  4. Ozh says:

    Aryan » I think I am exactly understanding what you want. Private install (password protected admin) *but* public stats and public API. Please re-read my replies and YOURLS doc.

  5. Aryan says:

    Can we have a private chat so i can explain you the whole think so we can sort my problem out ;)

  6. Aryan says:

    or you can send me a config.php file which suits my need

  7. Desde.boxes says:

    Hello Ozh.

    I have the same issue than Mark (#147). All things appears as OK, but plugin doesn't publish on twitter.

    Plugin creates short url OK, doesn't appear any error, but it doesn't post on twitter. New url appears on yourls installation, so wordpress->yourls works OK. Of course, I check three times user and password, and all is Ok.

    I can't see any errors in all logs I saw. Can you help us?

    Thanks in advance.

  8. Doug Smith says:

    Thanks so much for your work on YOURLS and the WordPress plugin!

    I have a quick question. Is there a way I could force the WordPress plugin to generate short URLs in the form of http://domain.com/POST-ID? This would have the advantage of my post URLs still working with a simple .htaccess rule if I stopped using YOURLS for some reason in the future.

  9. Ozh says:

    Doug Smith » as of now, it's not possible. This said, in a future version I'll add hooks into the plugin, and it would then be doable to do what you want with a simple companion plugin

  10. Desde.boxes says:

    Hello again!

    I thank you for the good work. Really it's fantastic.

    I still with same error, but now I looked for answers.

    I tried another hosting, another blog and the problem isn't solved. Then I came here and I saw most pages of "Blablas", and deactivate wordpress stats plugin. The issue continues.

    The short url is generated, so WP->YOURLS works. The communication WP->Twitter is where all fails.

    I looked for in twitter.php, and I found the pluggin only shows an error if the response to twitter contains something like "error" word. I'm not sure with this, I'm not programmer.

    So I went back to the plugin's page, changed my password to another wrong, and I tried one more time to publish a post. And the plugin told me "Success! Post was promoted". What does mean this?

    I want to solve my problem, but here is a idea for improve the plugin. Why does not the plugin show a "sucess!" if all was OK?

    Can anyone offers me a way to looking for a solution? Any words to search with google?

    Thanks in advance.

  11. Derek VOF says:

    Hi Ozh –

    Handy plugin. Seems to work great when I hit "Publish" from within WordPress, but if I schedule a post, it never makes it to Twitter. Is that a limitation of the plugin or am I missing a setting? The shortened URL is created and ready to go at the bottom of the page, but it never hits Twitter.

    Thanks!

  12. Ozh says:

    Derek VOF » I thought this issue had been fixed a while ago. Will have a look.

  13. Edmar says:

    Hello,

    I'm very happy with the yourls plugin. But, I'm having problem with my own yourls installation. The system had shortened correctly my URLs until finish the sequential
    numbers 1-8. After, when beggining letters, a, b and c was perfect. But, d sent to error page, "e" too, and now I couldn't use my own yourls.

    Excuse my bad english, but can you help me?

    You can add msn@edmarrp.org for this.

    Thank you.

  14. Hi!

    I like a lot Yourls and this plugin. I have a couple of "feature requests" for future development, I hope they are simple enough to be added:

    first one, can you use something else instead of "from API" to sign twits from this plugin? the optimum would be the name of the blog, like "tweetable" does

    second, changing the way it generates short urls: now it creates them with a sequential number, what about creating random urls?

    thank you and keep your great work ;)

  15. moh ini sin says:

    Ive configured everything, but still it's not working when i use scheduled posts.

    kindly help me..

  16. Nisse says:

    What should I write instead of "/home/you/"-part of the example for local installation?

    "Example: /home/you/site.com/yourls/includes/config.php"

    I can't figure it out.

  17. Ozh says:

    Nisse » the physical path of the config.php

  18. Sutherland says:

    Hey Ozh, thanks a ton for this plugin, it's been a huge help to me. With that said, it's worked flawlessly for the most part. Lately though, it started occasionally creating 2 short urls for the same long url at the time of posting. Initially my yourls installation was set to disallow multiple shorts, but somehow it managed to do it anyways and break the duplicate short urls. I fixed the problem of the broken short links by enabling multiple short urls for one long url, but it's still occasionally creating duplicates at the time of posting. How should I troubleshoot this, or what information do you need?

    Thanks again for the great plugin!

  19. BandonRandon says:

    Hey OZH,

    You may still be working on updating this to work with WP 3.0 and the updated wpme_get_shortlink functions. I just wrote a short blog about what I did to clean up the UI a little bit so there is only one defualt "Get Shortlink" button instead of adding a second. This should work with WP 2.8 and above still. http://bandonrandon.wordpress.com/2010/05/10/yourls-wordpress-plugin-update-for-3-0/

    Let me know what you think. I hope it's at least a little bit helpful in the dev of this plugin. Thanks!

  20. AGb says:

    FYI – I found that having special characters in my Twitter password would result in the WordPress to Twitter plugin fail (silently) to tweet the post and short url. Changing the password to just letters and numbers solved the issue.

  21. Ozh says:

    AGb » Interesting feedback. What kind of special chars?

  22. AGb says:

    Ozh – The special characters !@#$%^&*. It was a bit odd because it was inconsistent. I have used these in other passwords and not had problems with Twitter. But "&" seems the most troublesome. A single inclusion and it fails. Whereas it appears three or more (different) characters in a password are needed to produce an error.

    It was actually another application that was reporting authentication errors with Twitter accounts that exposed the problem. The dev there narrowed it down to the special characters. Once we changed the passwords to simple alphanumeric, the authentication errors stopped. YOURLS was having problems with these same accounts. Thus changing the login settings in YOURLS to alphanumeric, your plugin would then post to Twitter. Victory!

  23. Lars says:

    Nice plugin, thanks for that work! :) Will it be updated to oAuth because Twitter stops supporting basic authentication in June?

  24. Ozh says:

    Lars » yes

  25. Christian says:

    Hi,
    is it possible to exclude a category? I added a sideblog via posterous and this posts needn't to tweet.

  26. Ozh says:

    Christian » Look there http://code.google.com/p/yourls/issues/detail?id=248 this is a similar question

  27. Hi,

    My posts are posting to Twitter – but without the short URL.

    When I go to the edit page, I get the "bleh – the short URL service is uncontactable" message.

    I am running yourls on djckmn.com and my blog on brisbaneblog.info

    Both of these sites are on the same account at NearlyFreeSpeech.net

    Above, you said logging into Yourls should work IF WP was auto-updating. I was unable to upload pictures to WP until I followed the instructions in this article: http://snarp.dreamwidth.org/124165.html

    I was wondering if the fact that NFS runs in safe mode is what is stopping the plug-in communicating with the main yourls install? I've already tried changing all the files in djckmn.com to web group but that didn't do anything. I've also chmodded yourls-api.php to see if that would work, but that didn't help either.

    I have tried telling the plugin to check in /yourls-api.php, and /home/public/yourls-api.php – Neither of these has worked yet. I've tried several times to swap between the two of these, clearing my cache every time.

    Is there anything else you can suggest, or any more info you need?

    Thanks,

    David Jackmanson

  28. Ozh says:

    David Jackmanson » probably a case of not getting correctly the path to config.php, are you positive you didn't get it wrong?

  29. Do you mean I have the wrong settings in my config.php file? I don't *think* I do, because yourls is working when I open it in it up in djckmn.com/admin

    Should config.php have just 'http://djckmn.com' or 'http://djckmn.com/home/public'?

  30. Ozh says:

    David Jackmanson » I'm talking about getting the correct path of the YOURLS config.php (ie the /home/physical/path/to/yourls/config.php) so the WP plugin knows how to contact your YOURLS setup

  31. Ah ok. It's at http://djckmn.com/home/public/includes/config.php – I just double-checked to make sure.

    But I don't understand where to put this info into the WP plugin. I can only see a field asking for yourls-api.php.

  32. Ozh says:

    David Jackmanson » That's a URL. The path is probably /home/public/includes/config.php then. Just look at the options in the plugin: case if YOURLS and WP are on the same machine (not necessarily same domain name), ie "Local", or not on the same machine, ie "Remote".

  33. I've been using "remote webserver". Although the two sites are both hosted on nearlyfreespeech.net, they are two different sites with different IP addresses.

    I've tried switching to "local" but that generates an error message – telling yourls to use local path /djckmn/home/public/includes/config.php gives

    Warning: file_exists() [function.file-exists]: open_basedir restriction in effect. File(/djckmn/home/public/includes/load-yourls.php) is not within the allowed path(s): (/f5/brisbaneblog/:/nfsn/apps/php5/lib/php/:/nfsn/apps/php/lib/php/:/nfsn/content/content/nfsn/) in /f5/brisbaneblog/public/wp-content/plugins/yourls-wordpress-to-twitter/inc/core.php on line 129

    Warning: require_once() [function.require-once]: open_basedir restriction in effect. File(/djckmn/home/public/includes/config.php) is not within the allowed path(s): (/f5/brisbaneblog/:/nfsn/apps/php5/lib/php/:/nfsn/apps/php/lib/php/:/nfsn/content/content/nfsn/) in /f5/brisbaneblog/public/wp-content/plugins/yourls-wordpress-to-twitter/inc/core.php on line 134

    Warning: require_once(/djckmn/home/public/includes/config.php) [function.require-once]: failed to open stream: Operation not permitted in /f5/brisbaneblog/public/wp-content/plugins/yourls-wordpress-to-twitter/inc/core.php on line 134

  34. Ozh says:

    David Jackmanson » this is getting nowhere. What is the fucking *paths* of YOURLS on your setup? Physical path, not URLs, not domains, not IP. Path. What you see when you SSH or FTP. For instance the path of your WP setup is /f5/brisbaneblog/public/.

  35. Um, thanks for swearing at me. This no doubt seems simple to you but I'm struggling with it.

    When I log into my FTP client I see /home/public/includes/config.php

    My site information screen says my root path is /f5/djckmn

    Therefore I assume (athough I could be wrong) that the path to the yourls config file is /f5/djckmn/home/public/includes/config.php

  36. Dear Ozh,

    Seems like you're having a rough day. How's about you take a break from replying to David and come back when you're less stressed out.
    I know the feeeling and I do get like that sometimes with patients @ the hospital.

    Take care and BTW the plug-in/code still works pretty well on my blog. Have a fabulous weekend. Cheers ;-)

  37. Ozh says:

    David Jackmanson » Try /f5/djckmn/public/includes/config.php

  38. Ozh says:

    Udegbunam Chukwudi » looks like a sound advice ;)

  39. Hi, thanks for the reply.

    Unfortunately neither /f5/djckmn/public/includes/config.php

    nor /f5/djckmn/includes/config.php works.

    They both generate the same errors on the "edit post" screen as in my comment here of 29/May/10 at 1:11 am

  40. Ozh says:

    David Jackmanson » in other words, your host sucks. Sorry, don't know how to help you further.

  41. @David Jackmanson: I think it's about time you contact your web host with regards to this issue. As Ozh said your web host might be to blame. Who do you host with by the way?

  42. @Udegbunam Chukwudi,

    Sorry I didn't see this reply earlier.

    I'm hosted at NearlyFreeSpeech.net. I've been looking for help on the forums there for the last couple of days.

    They tell me it's likely the problem is caused by not using the $_SERVER['DOCUMENT_ROOT'] value to refer to the site's public directory, as detailed at:

    http://faq.nearlyfreespeech.net/section/programming/siterootphp#siterootphp

    Since I have no idea what this means I'm looking to pay for a php programmer who can alter the plugin for me or write a new one to amke it work.

  43. My advice to you would have been to change web hosts but if you are happy with them, you can stay put. In the mean time, you can check out this tutorial http://www.ampercent.com/branded-url-shortener-own-domain/6049/
    Cheers

  44. Ozh says:

    David Jackmanson » changes are you cannot use the local method. Thus you need to rely on the remote method, where you input the *URL* to yourls-api.php (like http://sho.rt/yourls-api.php). If that doesn't work, well, that doesn't work. Find a better host.

  45. Andy says:

    @David Jackmanson – I host my blog on nearlyfreespeech.net and I was using Ozh's plugin for about a month before it stopped working. I went through much of the same process as you but simply could not get it working.

    In the end, I ended up going with Shorten2Ping by Samuel Aguilera and it has worked flawlessly. It does essentially the same thing as Ozh's plugin.

  46. I figured out how to make this work.

    I'd already tried using the remote method, which hadn't worked – *that's* why I was providing URLs earlier in this discussion.

    What did work, however, was to upload a copy of the config.php file for the YOURLS install on djckmn.com into a directory of brisbaneblog.info

    Then I went to the settings, selected the "local" option, and entered the /f5/brisbaneblog/ …. config.php path into the settings of the WordPress plugin.

    This worked. The plugin was able to read the details from the config.php file stored in the brisbaneblog.info directory and use those details to tell the install hosted at djckmn.com to create the short URL, pass it back to the plugin and send a tweet containing the title of a new post and the short link to the brisbaneblog twitter account.

    Of course I could have also just installed YOURLS into a subdirectory of brisbaneblog.info but that would have made the short URL longer than I wanted – I wanted them in the form djckmn.com

    Hope this helps anyone else with the same problem.

    Andy, thanks for the info, too – if my last shot at making this work had failed a backup would have meant I still had some hair left!

  47. @David Jackmanson: Boy does it feel good to hear that you finally fixed it. Enjoy. ;-)

  48. Uwe says:

    Thx for the great work!

    Could you please make a selection to send an update tweet?
    Of course without making a new short url :-)

  49. Eddy says:

    Hi i have a problem with the Plugin.

    Haveing YOURLS installed on the same Server as my WordPress only got me some Error's with the Plugin.

    So I installed YOURLS on my Mac so i could use it as a Remote Webserver.
    I got rid of the Error's but now i get the Message "Bleh. The URL shortening service you configured could not be reached as of now. This might be a temporary problem, please try again later!" …
    How can it not connect to my Mac when its still running ?

  50. Tuinslak says:

    Are you sure this still works with WP 3.0? It's been working fine for months, and since I updated to WP 3.0 the shortening is broken and I get the usual error: "Bleh. The URL shortening service you configured could not be reached as of now. This might be a temporary problem, please try again later!"

    The Yourls is located on a remote server, and as I said, it's been working great for ages. Until recently. Tried changing the username/psw, using another domain as URL (in case it was a DNS prob), …

    Cheers

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.