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. Robert Mann says:

    Oh boy – my apologies. I did not see the update warning in the Admin window and so assumed it was up to date. Many thanks for the help.

  2. Mike Cohen says:

    Why is the plugin generating short links for all of my old posts (but not tweeting them)? I set it to shorten & tweet only when a new post is published. My database is getting filled with shortened URLS for old posts with 0 clicks. New posts are getting shortened & tweeted properly.

  3. Ozh says:

    Mike Cohen » See this explanation

  4. Mike Cohen says:

    My problem with that is I have many thousands of old posts in my blog, which is causing all of my new shortened URLs to be 3 or more characters, while the old ones that I never use have nice short 1 or 2 character URLs. I really need to get rid of that feature and purge my database of all of those unused URLS & reset the next URL so I can get nice short ones.

  5. Lync says:

    Couldn't update from v1.4.4 to 1.4.5. WP says "can't remove the former one" and i got an error but no further details. It just says "plugin.php error"… Any ideas?

  6. Ozh says:

    Lync » your WP setup cannot delete a plugin it seems. Delete via FTP and install newer one.

  7. Sami says:

    I was looking for a plugin that can create Short URLs of my own domain and use them for posts automatically associated with a tweet button. I mean something like TweetMeme button plugin. However TweetMeme does not allow to create or use short URLs of the WP installed domain. WordPress already has short URLS, even when the Permalink setting is using pretty links, the ugly URLs still work and will redirect to the pretty one. These can be added manually but what I wanted is add them automatically using a plugin.

    Your plugin has the ability to create short URLs of own domain but it is only used for My tweeting. I think you could easily add a tweet button feature that uses own domain URLs. And this is actually much more important for me than Me Tweeting my posts and will make a much bigger exposure for sharing your posts on twitter.

    Hope you add such thing, or if you know a solution, I'll be glad to know it.

    Thanks.

  8. Trent says:

    Hello, I run a blog in multiple languages using WPML. I'd really like to use your plugin to tweet posts out but there is a need to send the English version of the post to the English Twitter account, the French version of the post to the French Twitter account, etc. It would be amazing if there was the ability to set up multiple Twitter accounts and be able to choose which Twitter account the tweet would go to.
    I am a novice PHP programmer and might be able to get something working if you have any suggestions. I noticed in the oauth code it mentions that there is a "token override via parameter" but I'm not sure how I could change the parameters? Or perhaps there is another way to tackle it?
    Thanks.

  9. Joel says:

    There is an "issue" when categories are tweeted as hash tags and they contain spaces. A category like "My Caterogy" will be sent out as #My Category instead of #mycategory. Can you add this functionality? In the mean time, where can I edit the code so it removes spaces for categories?

    Thanks

  10. Ozh says:

    Joel » Will check this. I'm not on my dev box, can't remember off memory where the code would be

  11. Siva says:

    Thanks for the plugin.. can i replace Yourls logo with my logo ?
    I still place yourls link at the footer :)

  12. Ozh says:

    Siva » All the code I release is always free, as in "do whatever you want to do with it"

  13. Offray Luna says:

    Very nice. Stats are provided by the software of by an external service like Google?

  14. Rahul Bansal says:

    @Ozh

    I was planning to use this from long time. Now I ready with a nice short domain, I have only two questions.

    Can we use one setup of YOURLS across multiple wordpress blogs? Like for a blog-network.
    In that case, can we have some structure in hashes like: http://doma.in/b1-xxx, http://doma.in/b2-xxx and so on where b1 and b2 are 2 letters reserved for blog1 and blog2 in network?

    Thanks again, for great work as usual.
    -Rahul

  15. Ozh says:

    Rahul Bansal » no

  16. gordon says:

    I setup YOURLS with my own short domain (dew.is) and got your plugin working nicely — thank you for creating it! One thing I noticed just now when I posted something with tags that had spaces is that the resulting hashtags (predictably) only had the hash on the first word, though the other words were included in the tweet. (See http://dew.is/h7 for the tweet in question.)

    A possible enhancement would be to parse the tags for a post and remove the spaces so that you end up with a hashtag like #thisusedtohavespacesinit.

  17. Ozh says:

    gordon » indeed. Will fix this, thanks for the report.

  18. 4h18 says:

    Bonjour,

    J'ai un problème d'authentification avec la dernière version du plugin.

    J'ai beau autoriser encore et encore l'application à dialoguer avec mon compte Twitter, le plugin me renvoi toujours le message :"Could not Authenticate you".

    Où dois je chercher ?
    Merci.

  19. Priyadi says:

    Hi, like several users here, I had this same twitter error message:

    "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."

    After some debugging, it turned out that my PHP installation didn't have support for http streams. and thus couldn't do an fopen('http://…'). For those who get the same error, make sure 'http' is listed in the 'Registered PHP Streams' in phpinfo().

    In my version of PHP, I had to enable curl to have http support. IIRC, we used to have http stream support by default, even if we didn't enable curl.

  20. Ozh says:

    4h18 » Un plugin conflictuel peut-être? Sinon, je ne sais pas …

  21. rats says:

    @Priyadi… how? Also, alot of people have this problem. Why isn't there a fix?

  22. Ozh says:

    Priyadi & rats » I don't think this is accurate. My plugin uses the HTTP API from WordPress. This does not rely on fopen() or on streams. Aren't you running another plugin that's related to Twitter and has an oauth class too?

  23. rats says:

    Of course I don't. Proof: http://imgur.com/r9S00.png

  24. rats says:

    Nothing new?

  25. excon says:

    Hi Ozh
    great plugin worked for me since a year now i think combiened with my yourls shortner service.

    Yesterday i upgraded yourls to 1.5
    and your plugin to newest version as well 1.4.7

    Now all works yourls service
    your plugin generates the short as always.
    But it does not paste it any more into the twits on twitter

    when i switch to tinyurl works fine , but not anymore when i use my own yourls shortner. i have no clue at all why its stopped

    on your plugin page it says all green, sais as well connected to my twitter account and shows me my followers etc.

    Any help ?

    Thanks for Support if you got time

    ExCon

  26. roberte says:

    similar problem as excon. just upgraded to yourls 1.5. have 1.4.7 plugin installed too. before the upgrade, everything worked smooth. now on new posts, i get the "Bleh. The URL shortening service you configured could not be reached as of now" message.

    only after leaving the post edit screen and coming back, is the short url correctly created.

    any help to remedy this is much appreciated.

  27. Same problem like excon. Do you have an solution for that?
    Great plugin so far!

    Christian

  28. Sven says:

    Hello,

    I have a question – I installed YOURLS v1.5 and the WordPress Plugin (WP 3.0.1 is in use).

    I just saw in the YOURLS admin interface that the WP-Plugin automatically generate a lot of short url's (about 150) for my old articles. Is it possible to deactivate that "feature" or is it a bug?

    I thought the wp-plugin only generate short url's when I post a new article.

    These are my wp-plugin settings:
    – new article published (selected)
    – new site published (not selected)
    – new mediathek published (not selected)

    Thanks for your support
    Sven

  29. rats says:

    Ozh, still no support for the "Woah" error?

  30. Ozh says:

    rats » I definitely cannot reproduce anything like this

  31. rats says:

    You have my email, if there is a way that i can help, i would gladly do it. Also, i am not the only one experiencing this… Read it on the WP forums aswell

  32. Oliver says:

    Hey!

    Everytime when i activate the wp2twitter plugin my own yourls install generates wrong short-urls like this

    1. http://http%3A%2F%2Ftwty.de%2F7v

    this is the generated short-url of my own yourls install.

    1. http://twty.de

    why generates the plugin a short-url of my own yourls install?
    Why generates the plugin wrong short-urls?

    thank you!

    Oliver

  33. Ozh says:

    Oliver » my plugin hooks into the internal shorturl API to provide YOURLS short urls. Regarding wp2twitter, don't know this plugin, but it's probably doing something wrong. Disable it?

  34. Federico says:

    Hi Ozh, I have the same issue of comments #325 and #326, exact the same, after upgrade to YOURLS 1.5, the short URL is not tweeted… Any help?

    Thanks!!!

  35. Erdem says:

    Hi Ozh,

    I have the same problem with Federico. After i updated YOURLS and the WP plugin, the short URL is not tweeted anyway.

    Thanks for your help.

  36. matt says:

    hey Ohz, same problem here with the plugin making links correctly but not tweeting them. The only other thing I noticed on my install that could be amiss is that when I type the url for the yourls-api, the "check" returns "Not Found" though the url and permissions are definitely correct. I have yourls running on it's own dedicated machine hosted on godaddy. I don't know if that's even an issue since it DOES make the short URLs immediately after I make a new post on WP, just thought I'd mention it. Any help on the lack of tweets would be great.

    Thanks!

  37. Hello,

    Same problem here ! the plugin making links correctly but not tweeting them..
    – Yourls 1.5
    – YOURLS: WordPress to Twitter 1.4.8

    is it this changeset the problem source ?

  38. Ozh says:

    Frédéric Cozic » No. It's just a filter, which does nothing if you don't have any plugin using that filter.

  39. ok so there's still a problem :(

  40. Hi!

    My solution for this problem is still to tweet manually. After the post is published, i press the button "Tweet this".

    I like this way too.

    Christian

  41. Sebastian says:

    Hi there,

    I, too, have a problem with the plugin. YOURLS is running fine on my server http://b1t.me – I've set up the WordPress plugin (ver. 1.4.8) and even though my yourls-api IS reachable under the address:

    http://b1t.me/yourls-api.php

    after clicking on the "check" button the plugin keeps telling me "not found". Nevertheless the red cross on top of the configuration section turned into the green tick…

    After posting a new article, 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!"

    Any idea what I might be doing wrong here?

    Cheers,
    Sebastian

  42. Ozh says:

    Sebastian » if the plugin tells you "not found", then it won't work further. Try changing the YOURLS location to remote or local.

  43. Sebastian says:

    You're right – that fixed the problem – thanks. As both websites (the WordPress Blog and the YOURLS installation) are running on the same machine (even though they have different domains) I had to chose "installation on the same server" and then use the path to my config.php file.

    So now the URLs are shortened correctly :-)

    The next problem I now have is that my posts are not being tweeted automatically – I'm using Christian's solution for the time being. But is there any solution to the "URLs are shortened correctly but Tweets are not sent automatically"-problem?

    Thank you so much for your great plugin and your help in your blog!

    Sebastian

  44. Eric says:

    According to my WordPress install, I am using Version 1.4.8.

    I do not get just the consumer key and consumer secret boxes — it also has access token and access token secret boxes for me to fill in.

    It does not do the oauth authentication as per your screen shot above. And I cannot get access token and access token secret.

    Any suggestions for how to get the plugin to act like it does in your screenshot?

  45. Eric says:

    I deleted the plugin and downloaded a fresh copy from WordPress.org.

    Unlike your picture above, my plugin says:

    To connect your site to Twitter, you need to register your blog as a Twitter Application and get a Consumer Key, a Consumer Secret, an Access Token and an Access Token Secret. Phew. Complicated? Blame Twitter :)

    Now no matter how I try to set it, it says on every admin screen "YOURLS – WordPress to Twitter configuration incomplete"

    So I am trying, but as you say a picture is worth 1000 words and I can't figure out why my plugin screen doesn't look like the one shown above.

  46. Ozh says:

    Eric » Because I didn't update the portion of the screenshot about authentication when I updated the plugin.

  47. Eric says:

    Perhaps I could be clearer. It probably doesn't matter so much whether the admin panel matches your image or not so much as that I can't get it to work.

    Better yet – apparently I have an insane problem.

    Same WordPress install – at the same time – logging in from two different computers.

    On my main computer (new machine running Vista with 6GB ram etc.) when going to my WordPress site it has a red exclaimation point next to Twitter settings and says "Could not authenticate you.".

    On a ten year old machine running linux and barely able to open web pages because it is so under-powered the Twitter settings has a green check and it shows me properly logged in to Twitter with my username.

    So I was able to figure out the settings correctly and put in the correct values. I have no idea why the admin screen would show different results on two different computers.

  48. Igor says:

    I can´t find the config.php file.

    This file shouldn´t be inside the plugin folder?

    I have the folder /public_html/wp-content/plugins/yourls-wordpress-to-twitter but there´s no config.php there?

    How do I find it?

  49. Ozh says:

    Igor » the config file for YOURLS

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.