Warning: Creating default object from empty value in /home/planetozh/planetozh.com/blog/wp-content/plugins/paged-comments/paged-comments.php on line 31

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/planetozh/planetozh.com/blog/wp-content/plugins/paged-comments/paged-comments.php:31) in /home/planetozh/planetozh.com/blog/wp-content/plugins/yourls-wordpress-to-twitter/plugin.php on line 73

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/planetozh/planetozh.com/blog/wp-content/plugins/paged-comments/paged-comments.php:31) in /home/planetozh/planetozh.com/blog/wp-content/plugins/yourls-wordpress-to-twitter/plugin.php on line 73

Warning: Cannot modify header information - headers already sent by (output started at /home/planetozh/planetozh.com/blog/wp-content/plugins/paged-comments/paged-comments.php:31) in /home/planetozh/planetozh.com/blog/wp-content/plugins/wp-super-cache/wp-cache-phase2.php on line 62

Warning: Cannot modify header information - headers already sent by (output started at /home/planetozh/planetozh.com/blog/wp-content/plugins/paged-comments/paged-comments.php:31) in /home/planetozh/planetozh.com/blog/wp-content/plugins/ozh-who-sees-ads/wp_ozh_whoseesads.php on line 630

Warning: Cannot modify header information - headers already sent by (output started at /home/planetozh/planetozh.com/blog/wp-content/plugins/paged-comments/paged-comments.php:31) in /home/planetozh/planetozh.com/blog/wp-content/plugins/ozh-who-sees-ads/wp_ozh_whoseesads.php on line 631

Warning: Cannot modify header information - headers already sent by (output started at /home/planetozh/planetozh.com/blog/wp-content/plugins/paged-comments/paged-comments.php:31) in /home/planetozh/planetozh.com/blog/wp-content/themes/planetozh/functions.php on line 172

Warning: Cannot modify header information - headers already sent by (output started at /home/planetozh/planetozh.com/blog/wp-content/plugins/paged-comments/paged-comments.php:31) in /home/planetozh/planetozh.com/blog/wp-content/themes/planetozh/functions.php on line 173
YOURLS WordPress (a Short URL Plugin) « planetOzh
On: 2009/06/25 Viewed: 58359 times
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 the plugin : yourls-wordpress-to-twitter.zip
Extract and upload to your blog, preserving directory structure.

Note: the plugin requires PHP 5 to run.

Template Tags for you theme

The plugin comes with two template tags:

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

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:

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


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

    Pages: [1] 2 3 4 5 6 7 8 9 10 » Show All

  1. 1
    gidibao Italy »
    said, on 25/Jun/09 at 10:35 pm # :

    Thanks so much for this awesome plugin.

    You rock!!! ;-)

  2. 2
    Ozh France »
    replied, on 25/Jun/09 at 10:44 pm # :

    Hey I'm still writing the page :)

  3. 3
    gidibao Italy »
    said, on 25/Jun/09 at 11:54 pm # :

    Ozh – your WP-reputation worth a thousand plugin tests!

    "YOURLS: WordPress to Twitter" sounds great… I Trust in You :-)

    Regards as always


  4. 4
    YOURLS: Your Own URL Shortener « B... Singapore »
    pingback on 26/Jun/09 at 10:43 am # :

    […] Check out Ozh blog post on the WordPress plugin, YOURLS: WordPress To Twitter (a Short URL Plugin). […]

  5. 5
    Lester Chan Singapore »
    wrote, on 26/Jun/09 at 12:46 pm # :

    I must say this, this plugin is leet!

  6. 6
    Sujit India »
    said, on 30/Jun/09 at 8:46 am # :

    Hi there…!!!
    I am using your 'yourls script' to shortern my urls. And i am also using the wordpress plugin.

    I need to make a feature request….!!! :)
    Can you add the support for http://su.pr in the plugin. Its a new short url website from stumbleupon.com

  7. 7
    Sujit India »
    thought, on 30/Jun/09 at 9:13 am # :

    BTW, they are letting new users signup with invitation codes. If u need one, please do let me know where i can send one. Do mail me at sujit[@]netsujit[.]com

  8. 8
    WordPress Plugin Releases for 06/30 | We... United States »
    pingback on 30/Jun/09 at 8:03 pm # :

    […] YOURLS: WordPress to Twitter […]

  9. 9
    9npc China »
    commented, on 01/Jul/09 at 11:47 am # :

    Sorry. I have a problem, when I click "Tweet this", an error prompt is "Error during Ajax request: Internal Server Error".

  10. 10
    Ozh France »
    replied, on 01/Jul/09 at 12:21 pm # :

    9npc » Misconfiguration on your side. Can't help without more info

  11. 11
    Alex Brazil »
    commented, on 01/Jul/09 at 8:02 pm # :

    Hi Ozh,

    Thanks for this plugin. Here is some feedback: After I activated the YOURLS plugin, my "Edit Post" screen went blank. As I deactivated the plugin :( everything went back to normal. I'm using WP2.8.1 beta2 with K2 theme and Firefox.

  12. 12
    Ozh France »
    replied, on 01/Jul/09 at 8:59 pm # :

    Alex » Haven't heard about a similar issue. It's running fine both on 2.8 and 2.9 (trunk). Is there a JS error? Something that could help find what's going wrong?

  13. 13
    Alex Brazil »
    said, on 02/Jul/09 at 1:21 am # :

    Ozh, I know it sound surreal, but I didn't get any JS error message that I could see. You know, maybe it's some sort of plugin incompatibility, since I currently have 38 of them active. Not to worry, I will patiently (but eagerly) wait for a future releases/updates. Thank you for your kind reply above, and thank you for all your wonderful plugins!!!

  14. 14
    Chuck United States »
    replied, on 02/Jul/09 at 4:27 am # :

    Today, I published a draft post in WP (about a week old), no Tweet automatically happened – I went in and edited the post – and hit the 'tweet this' button, and got "Bleh. Could not promote this post on @cvillevegan. Maybe Twitter is down? Please try again later!"
    I know the password is correct – and the link to @cvillevegan worked too

    Downloaded the most current (today) version of YOURLS

  15. 15
    Ozh France »
    said, on 02/Jul/09 at 7:31 am # :

    Chuck » In next version I'll had a "Test connection" in the option page to check things

  16. 16
    9npc China »
    wrote, on 02/Jul/09 at 7:54 am # :

    Thank you very much,Today I check the server configuration, the problem is solved, and now it has been running. I love this plugin so much.^^

    But I have a little problem.when I click “Tweet this”, and got "Bleh. Could not promote this post on @9npc. Maybe Twitter is down? Please try again later!"

    Finally, I am so sorry, because my English was so bad.

  17. 17
    Daniel Germany »
    said, on 03/Jul/09 at 11:25 pm # :

    The "blank edit screen" issue happens when YOURLS is used together with the "Twitter Tools" plugin. Deactivating either helps. Looking for a fix now.

  18. 18
    Daniel Germany »
    commented, on 04/Jul/09 at 12:10 am # :

    Fixed the problem. In core.php I've changed the yourls-remote api call from JSON to simple:

    case 'yourls-remote':
    $api_url = sprintf( $wp_ozh_yourls['yourls_url'] . '?username=%s&password=%s&url=%s&format=simple&action=shorturl',
    $wp_ozh_yourls['yourls_login'], $wp_ozh_yourls['yourls_password'], urlencode($url) );
    $shorturl = wp_ozh_yourls_remote_simple( $api_url );

  19. 19
    mrbromley Switzerland »
    replied, on 08/Jul/09 at 10:58 am # :

    Loving the home brew shortener, any chance of including Stumbleupon's 'su.pr' short code service in the plugin's public list. This be very useful. Thanks-in-advance!

  20. 20
    Stefan Switzerland »
    said, on 09/Jul/09 at 11:51 pm # :

    Very awesome! already using it and it works like a charm.

    thanks a lot :)

  21. 21
    Stefan Switzerland »
    wrote, on 10/Jul/09 at 12:24 am # :

    I have one little feature request. It would be nice to have a template tag (or arguments) that only displays the shorturl (not a link) to make retweet links like this http://twitter.com/home?status=postingtitel shorturl

  22. 22
    Nic New Zealand (Aotearoa) »
    replied, on 12/Jul/09 at 6:49 am # :

    Hi, this looks brilliant! Merci :)

    I am running into a problem though and it\'s driving me batty!

    When I save a post, I get the following errors:

    1. Warning: gzinflate() [function.gzinflate]: data error in /home/username/public_html/wp-includes/http.php on line 1787
    3. Warning: gzuncompress() [function.gzuncompress]: data error in /home/username/public_html/wp-includes/http.php on line 1792
    5. Warning: Cannot modify header information - headers already sent by (output started at /home/username/public_html/wp-includes/http.php:1787) in /home/username/public_html/wp-includes/pluggable.php on line 865

    I\'ve looked at the FAQ and made sure to remove trailing spaces. This has not helped. I\'ve looked to see other plugins were not getting in the way.

    Do you have *any* idea what might be the problem?

    Merci d\'avance pour toute aide rendue.


  23. 23
    WPGPL Team Indonesia »
    wrote, on 12/Jul/09 at 4:30 pm # :

    Wow, I like it, I will try it someday

  24. 24
    How Simple To Create Your Own URL Shorte... United States »
    pingback on 19/Jul/09 at 9:08 pm # :

    […] and looking for Open Source based service, whatever php or mysql based or free service and finally A Short URL Plugin by Ozh give me a great solutions at yourls.org and that will merge two website and will make a bridge in […]

  25. 25
    ?? Yourls ????????? - Showfom's Blog China »
    pingback on 01/Aug/09 at 2:23 am # :

    […] Twitter ??????? API ????Ozh ????? Template Tags<?php if (function_exists('wp_ozh_yourls_url')) […]

  26. 26
    Alex W United States »
    commented, on 03/Aug/09 at 5:44 pm # :


    Are you planning to add support for Su.pr to your already-awesome plugin?


  27. 27
    Lane United States »
    commented, on 04/Aug/09 at 3:44 am # :

    Love this setup, but I've found a little snare, for some reason when activating this plugin, it's preventing being able to edit pages. Everything on a page edit shows except the main content area where you can edit the actual content. Once you deactivate the Yourls plugin, it shows up. Using WordPressMU 2.8.2, Yourls 1.2. and Yourls: WP to Twitter 1.1.

  28. 28
    Lane United States »
    said, on 04/Aug/09 at 4:02 am # :

    Hmm, only breaks when you activate the Yourls plugin "site wide" through MU. If you activate it per blog, it doesn't break the page editing.

  29. 29
    joshnunn Australia »
    thought, on 05/Aug/09 at 6:08 am # :

    I'm loving the plugin, but I have a couple of questions/suggestions:

    1. Using the wp_ozh_yourls_head_linkrel() template tag on the front page of a wordpress blog seems to insert the yourls link for the latest post, instead of the link for the main URL (eg. main site nunnone.com has tiny url e01.li/8u which actually leads to my latest post, rather than back to nunnone.com)

    2. I'd like to second Stefan's suggestion for a tag that will just insert the raw short link, so I can craft my own links and use the links in other ways.

    3. I get the "Bleh. Could not promote this post" error as well, but the post happens anyway. Is there some sort of log we can get to you to help track down why it might be happening?

    4. I had to turn off automatic posting to twitter, because for some reason it caused short urls to be generated for preview pages as well as the final page, and then publishing the page would generate an error. As with the previous problem it didn't actually prevent the posting, but it's strange behaviour. Again, if there's any more information I can provide I'd be glad to.

  30. 30
    Ozh France »
    wrote, on 05/Aug/09 at 10:30 am # :

    joshnunn » 1. As stated in the doc, "Suggested use: in header.php, if is_single() or is_page()" so it's not supposed to be triggered on the home page. I guess I should add an internal test in the plugin itself.
    2. You can use wp_ozh_yourls_geturl( $id ) where $id is the global id of the post.
    3. Using Firebug, you can see what was the actual XML response to the AJAX request
    4. Will do some tests and update the plugin if I can find something to fix

  31. 31
    Sujit India »
    said, on 07/Aug/09 at 5:18 pm # :

    Hi there…!!!
    Its me again, sujit !!! :D

    One more feature request from my side.

    It will be really nice if you add support to push the new post to ping.fm. In that way, the new post with the short url can be published in different social networking website.

    Please try to add the support of ping.fm

  32. 32
    Ozh France »
    commented, on 07/Aug/09 at 8:32 pm # :

    Sujit » I'll have a look at ping.fm and their API

  33. 33
    Sujit India »
    wrote, on 10/Aug/09 at 2:13 am # :

    Thanks OZH…. :)

    Please take your time and do let us all know if you provide support to ping.fm
    Very few plugins are there that support ping.fm. There's one such plugin…"Shorten2Ping"… which shorten the url and then publishes the post to ping.fm. But i prefer "YOURLS" because of its speedy process and urls on my own domain.

    Once again thanks for looking in. Please do let us know your decision… :)


  34. 34
    azakers United States »
    said, on 10/Aug/09 at 11:12 am # :

    wow – just ran across this and I'm LOVING it.

    I ran through the documentation and comments to see if there was a template tag to render just the short URL – looks like there is not.

    Is thee a way to accomplish this through another call? I would love to specify the short URL in my retweet button.

    Loving it – looking forward to using it!

  35. 35
    azakers United States »
    replied, on 10/Aug/09 at 11:40 am # :

    So for my own purposes I modified a copy of the wp_ozh_yourls_url() function on plugin.php to accomplish what I was trying to do (pull a clean short URL string)

    // Template tag: echo short URL for current post
    function wp_ozh_yourls_url() {
    global $id;
    $short = wp_ozh_yourls_geturl( $id );
    if ($short)
    echo "$short";


    // Template tag: echo short URL only
    function wp_ozh_yourls_urlonly() {
    global $id;
    $short = wp_ozh_yourls_geturl( $id );
    if ($short)
    echo "$short";

    Now I can use wp_ozh_yourls_urlonly() to pull just the clean URL string. I'm a total PHP noob so there's likely a much easier way to accomplish this, and I probably shouldn't *suggest* modifying the plug-in files etc, but its a quick and dirty way to accomplish it for now.

  36. 36
    Create your own URL shortener for WordPr... United States »
    pingback on 12/Aug/09 at 12:10 pm # :

    […] Links: YOURLS PHP script official site YOURLS: WordPress To Twitter (a Short URL Plugin) – Author page YOURLS at the WordPress Plugin repository Bookmark and Share […]

  37. 37
    this could be a better wp plugin for sho... United States »
    pingback on 15/Aug/09 at 7:13 am # :

    […] http://planetozh.com/blog/yourls-wordpress-to-twitter-a-short-url-plugin/   […]

  38. 38
    Stefan Switzerland »
    thought, on 16/Aug/09 at 12:26 am # :

    Thanks to the reply from ozh and hints from a friend I figured it out. To get the raw url use this code in your template (inside the loop):

    1. post_id); ?&gt;

    Thanks for the awesome plugin!

  39. 39
    Stefan Switzerland »
    said, on 16/Aug/09 at 12:28 am # :

    Argh, lets try again :) To get the raw url use this code in your template (inside the loop):

    1. echo wp_ozh_yourls_geturl($post-&gt;post_id);
  40. 40
    azakers United States »
    wrote, on 16/Aug/09 at 4:10 am # :

    hah – I KNEW there was probably a much simpler way of doing it. Thanks for sharing that!

  41. 41
    Jamie United Kingdom »
    wrote, on 17/Aug/09 at 9:34 am # :

    Hi Ozh. Thanks for your work!

    I'm having a problem that I think has something to do with my .htaccesss file.

    My file was created automatically by WordPress when I changed the Permalink structure on my site. It looked like this:

    # BEGIN WordPress

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    # END WordPress

    Obviously this didn't work until I added the extra part from the YoURL code.

    The problem is that my Feed address now redirects to my homepage. I tried the Feedburner plugin to redirect my Feed url to my Feedburner url but it still redirects to my Homepage.

    If you (or anyone) can advise what my .htaccess file should look like, I would really appreciate it. If I'm barking up the wrong tree, a pointer would be useful!!

    Many thanks in advance.


  42. 42
    Ozh France »
    replied, on 17/Aug/09 at 5:32 pm # :

    Jamie » Not sure if this is what you're trying to do, but WP and YOURLS cannot sit in the same base directory. If so, requesting site.com/facebook could be either a blog post or a redirection link and there would be no way for the server to guess which option to take.

  43. 43
    Jamie United Kingdom »
    replied, on 17/Aug/09 at 8:52 pm # :

    Hi Ozh,

    Yes, you were spot on, I was trying to run everything from the base directory.

    I have now moved YoURLs to the tintent.com/yourls/ directory but now I get a 404 nothing found for my short urls.

    I started again with the .htaccess files. The one in the base directory is as above (produced by WordPress). There is also one in the /yourls/ directory. Do I need to do anything with these?

    Thanks again,


  44. 44
    Ozh France »
    said, on 17/Aug/09 at 9:08 pm # :

    Jamie » The .htaccess for YOURLS should work just as provided. Make sure you updated your config.php after moving directory, especially YOURLS_SITE which I bet you left to previous value pointing to root

  45. 45
    Jamie United Kingdom »
    thought, on 17/Aug/09 at 9:15 pm # :

    Now who feels stupid?!!!!

    It's fixed – THANK YOU!


  46. 46
    YoURLs – Getting It Right | Tinten... United States »
    pingback on 17/Aug/09 at 10:20 pm # :

    […] The first mistake I made was to try and install YoURLs in the same base directory that I have WordPress in.  You can't do this!  It led to a problem with my site's RSS Feed which was impossible to resolve.  However, I didn't realise this so I was forced to ask the author Ozh for help.  He replied very quickly through the comments on his YoURLs blog page. […]

  47. 47
    Shai United States »
    wrote, on 20/Aug/09 at 10:21 pm # :

    Wow, that is the best screenshot and description I've ever seen for ANY wordpress plugin. great job on this!

  48. 48
    Ozh France »
    replied, on 20/Aug/09 at 11:30 pm # :

    Shai » what? you mean you don't know my other plugins? :)

  49. 49
    mark beekman United States »
    wrote, on 21/Aug/09 at 9:00 pm # :

    I'm running wordpress on dreamhost and having trouble getting the WP plugin to ping twitter from the post page. Keep getting the "Bleh…" message. I've tried getting it to work w/ all 3rd party URL shorteners, my own, disabling all plugins (except Yourls), delete/reinstall Yourls plugin, deleting all other twitter related plugins, resetting the plugin folder, etc.

    Any other suggestions. Any server side changes needed?

  50. 50
    Ozh France »
    commented, on 21/Aug/09 at 9:51 pm # :

    mark beekman » running on dreamhost too. Check what is the Ajax response when you send the tweet, using Firebug on Firefox

Pages: [1] 2 3 4 5 6 7 8 9 10 » Show All

Leave a Reply

Comment Guidelines or Die

  • HTML: You can use these tags: <a href=""> <em> <i> <b> <strong> <blockquote>
  • Posting code: Post raw code (no <> &lt; etc) within appropriate tags : [php][/php], [css][/css], [html][/html], [js][/js], [sql][/sql], [xml][/xml], or generic [code][code]
  • Gravatars: Curious about the little images next to each commenter's name ? Go to Gravatar.
  • Spam: Various spam plugins on patrol. I'll put pins in a Voodoo doll if you spam me.
  • I will mark as Spam test comments, all comments with SEO names (ie "My Cool Online Shop" instead of "Joe") or containing forum-like signatures.