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

    @Ozh

    I uderstood that this is the config of yourls. But I still don´t know where this file is?

    Do I have to created? Do I have to download it and put into the same directory of yourls?

    The zip file´s plugin doesn´t have this config.php.

  2. Ozh says:

    Igor » of course the plugin doesn't contain the config file. It belongs to another software. YOURLS. That you have installed somewhere. That's where the config file is. Can't explain more. If that's still unclear, sorry, it probably means this plugin is not what you think it is and is not for you.

  3. Hugh Guiney says:

    I've set up everything correctly on my remote YOURLS installation—I can log in to the admin panel and create short URLs manually, and I can reach the yourls-api.php page which returns an XML response—but the WordPress plugin still says "Not Found" when I check it. What could be causing this? I'm hosted on NearlyFreeSpeech.NET, which has security measures such as PHP safe_mode enabled. Could that have any effect on this? Are there certain permissions that have to be set?

  4. Ozh says:

    Hugh Guiney » this is probably plugin misconfiguration, even if YOURLS is properly set up.

  5. Hugh Guiney says:

    What could be misconfigured? I have green check marks for all of the sections.

    I just did some debugging in the source code, and had the check expose the JSON request URL to me, which I then pasted in my browser, and I received a result with a 200 status. So I know that my authentication is correct, that the query was built properly, and that it works on the backend.

    The problem, then, has to be that the script can not connect to, or read the response from, the remote host. But I don't know what could be causing that.

  6. spiritofnine says:

    This plugin works great. Thanks for the awesome work!

  7. Uwe says:

    Your plugin is great – thanks!

    There are two things that would it make awesome:
    – different twitter text for page, post and post types
    – different twitter text for first published and update

    Would this be possible?

  8. panda4ever says:

    I have a problem installing this plugin, it dont want to save twitter Consumer Key and Access Token.
    Dont know why. I have obtained them from twitter, but still dont want save them.
    Wp 3.1 plugin 1.4.8
    Where can be a problem?

  9. John says:

    Your current version, as of 2011/02/28/, breaks the "Twitter Settings" page.

  10. gordon says:

    Hi…

    I've been having problems with the YOURLS plugin for the last day or so. When a new post is published, the tweet goes out, but without the link. I've checked my settings and everything appears to be ok, other than there aren't stars in my YOURLS password field (but I don't recall whether there were in the past).

    Is there a boundary condition going from February 28th to March 1st that has been lurking in the code, perhaps, with the code expecting a February 29th this year or something?

    I'm running WP 3.1, so I can't rule out this being something induced by the new version, though I have had posts under 3.1 tweeted out properly prior to yesterday.

  11. Jon Stout says:

    I'd like to include the first part of the body text of the WordPress post instead of the title. Is there a token, or a way to configure the %F token to do this?

    Thanks!

  12. jk says:

    like john (http://planetozh.com/blog/?page_id=1272&cp=36#comment-143901) panda4ever (http://planetozh.com/blog/?page_id=1272&cp=36#comment-143883) and gordon (http://planetozh.com/blog/?page_id=1272&cp=36#comment-144127), the plugin has unexpectedly stopped creating links in the last couple of days.

    i'm using wordpress 3.1 and i've tried turning off the other plugins, but for whatever reason it is no longer saving info entered into the twitter settings page.

    please advise.

  13. Ozh says:

    To All » I'm going to investigate the "no longer saving Twitter stuff" issue

  14. gege2061 says:

    Hello,

    Have you planned statusnet integration in addition of twitter?

  15. Ozh says:

    gege2061 » No

  16. John says:

    I should add, it's a WordPress 3.1 issue. It broke after the update.

  17. Eric Martin says:

    I really wanted to use this plugin, but could not get the Twitter settings to work.

    I narrowed it down to the following code in yourls.js:

    1. // On form submit, first reset all pwd fields
    2. $('.y_submit').click(function(){
    3.     password_hide_all();
    4. });

    I was able to get things working by commenting out the password_hide_all() line.

  18. Makis says:

    Add me to the line for the post update to twitter issue :D

  19. hello,

    Check my login and password only says it is invalid.

    But it is the same that I use to log on every day of my installation yourls

  20. Jim Hankins says:

    WordPress 3.1 update breaks your plugin :(

  21. BJ Johnson says:

    Got a question on interaction with Sitewide Tags. When a new post is published, YOURLS generates a short URL and tweets. Sitewide Tags picks up the new post and pulls it over. A Second tweet shows up in the Twitter stream but with a short URL next in the auto-generate sequence. But, YOURLS WordPress to Twitter isn't activated on the Tags blog. I'm stumped.

    Having two short URLs is okay, I suppose, as the canonical is set to the permalink, although it eats up available URL codes, but it seems it'd be better if there were only one for each post, no matter where it is displayed.

    OTOH, if YOURLS could have a setting to delay the tweet from the Tags Blog, that might be a feature BUT posts on the Tags Blog aren't readable there; *except* by following the short URL (this was news to me). All of the permalinks point to the original post on their respective source blogs.

    One thing that might be a clue is that the shortlink in the head for the original post is a YOURLS link but the one on the Tags Blog is a post id; even though the YOURLS shortlink is in the custom fields. How did it get there and why isn't it being used? Doubly stumped.

  22. panda4ever says:

    Thanks a lot for plugin fix.

  23. Makis says:

    Thanks for the update.
    I still cant fix my update problem though… :( like fix was never applied

  24. John says:

    Fixed, AFAICT.

  25. Jon Stout says:

    Hi there,

    Sorry if this is a stupid question, but I can't find any info on this in this comments thread or anywhere else. Is it possible to use the body of a post (if think it's the_content) instead of the title. I know it would truncate to fit, but my client really wants it. Thanks for any tips.

  26. Ozh says:

    Jon Stout » you can't get that as is

  27. Hi,

    hello, where do I find a tutorial step by step explain how to configure the remote server (webserver) along with the plugin in wordpress, because fiddling it move and months that I can not run the damned.

    /=

  28. Marco says:

    Great plugin!! Thank u ;)

  29. Shaun says:

    Hi there,

    I dont know if it has been asked before but I downloaded the latest version (at least it was featured 1.5) and when I am in the admin panel, the admin-ajax.php wants to download rather than execute to edit/delete saved URLs. From experience, I presume something is messed up in the coding.

    Any ideas on how to fix this?

  30. Andrew Shell says:

    The plugin is great however I wish it didn't require all the twitter functionality. Would you consider releasing a stripped down plugin or adding some options to this one so it could just be used as a url shortener api for themes and other plugins? If someone doesn't use twitter, but wants to generage a YOURL to publish to facebook or identi.ca it's frustrating to require connecting to twitter. My particular use case is I am creating a microblog theme with a custom quickpost bookmarklet and I'd like a plugin that allows me to work with YOURLS in the same way the "Bit.ly Service" plugin works with bit.ly.

  31. Ozh says:

    Andrew Shell » I won't make & maintain a separate plugin, but Otto has made one already: http://otto42.com/8y

  32. Martin Fuchs says:

    Hi Ozh,

    Great plugin and generating Short URLs works great! However, I noticed that after installation the YOURLS "widget" showing the short URL on the Edit Post screen shows up fine. When I create a new page it shows up as well. But it does not show up when I edit an older page which was created before I installed the plugin. I also checked in the Screen Options but YOURLS is not there. When I update an older page and check my YOURLS database I do however see that a short URL was created. I just don't see the box in the right bar of Edit Page screens. Tried deactivating plugins I had but that didn't help.

    Do you maybe have an idea why that could be?

    Thanks a lot,
    Martin

  33. Bjantiques says:

    sorry but got a problem.

    if i select
    Your YOURLS installation is on local server

    it asks for Path to YOURLS config.php

    but there is no config.php in your zipped file.

    please advise on solution.

    Bj

  34. Ozh says:

    Bjantiques » Read the doc. This plugin is a bridge between your blog and your YOURLS setup. You need a YOURLS setup somewhere.

  35. Edmar says:

    Hi, OZH,

    My blogs use wordpress. I install yours when it was in 1.4.3 version. Now, when I updated the last version, I'm having one problem for to acess the twitter account. The same problem is afecting my two blogs (http://www.unipress.blog.br and http://www.microcredito.blog.br). I created the twitter's aplication, when it was required and the plugin was normal, but in last version I have the problem.

    Can you help me?

  36. Lulu says:

    Hi Ozh,

    Just wanted to say I love your yourls plugin for wordpress!

    Now, I just updated my wordpress, and suddenly the plugin can't connect to Twitter any more. Says it could not authenticate me, and at the top it announces "YOURLS – WordPress to Twitter configuration incomplete"

    I have not changed anything on my twitter account either – in fact I retyped in the consumer key/secret and access key/secret, twice. But it still won't link when I refreshed.

    Any ideas?

  37. Olly says:

    Hi Ozh

    Loving YOURLS, but having a bit of trouble with WordPress 3.1.2. If the plugin is enabled I just go to a blank post.php when I publish a post. Post is published, but no tweet. Twitter settings are fine, YOURLS settings are fine (the entry is generated to be seen in admin interface) and this happens even if it's not set to alert Twitter.

    Any ideas?

    Cheers

    Olly

  38. Sy says:

    Hello ,

    I've authenticated myself , posts are submitted as usual , but no tweets are published , as well as it shows could not authenticate you .

    Can you help me out ? :(

    Thanks !

  39. Gene Locklin says:

    Thank you for updating yourls with the unicode plugin. Is there any chance of the WP plugin being updated to show my unicode url?

  40. Ozh says:

    Gene Locklin » by unicode I assume you mean IDN? I'll have to think about this. It'll be probably a companion WP plugin (I won't bloat the main WP plugin)

  41. Gene Locklin says:

    Ozh, Yes. I meant IDN. I'm looking forward to finally using my shortlinks on my site. Cheers!

  42. Leandro says:

    Hi. I've installed this plugin to wordpress and I've configured it. When I publish a post the yourls url is like http://http%3A%2F%2Fwww.leandrovidal.com%2F2011%2F06%2F05%2Fx%2F what's the problem?

  43. Nick says:

    Hi,

    Thanks for this plugin – it's great.

    Is there a way to append information to the short URL? For example http://domain.com/123?source=NewsletterJun11 or http://domain.com/123/?source=NewsletterJun11. When I try to use one of these links I get a 404 not found error. Unfortunately I cannot append the source to the original URL as the information is appended to the short URL by the mail client (Mailchimp) in HTML newsletters to track link clicks by email campaign in google analytics.

    Any suggestions?

    Thanks!
    Nick

  44. Fyrtek says:

    Hi there! Currently trying to integrate this plugin into my WordPress installation but I'm having trouble. When I click on the "in this help screen" which would show me how to enter the details for "register your application", it will load the small css window but will not show any of the guide.

    It used to show this (have installed this on two other installations) but am having trouble trying to get that info now. Hope you can help!

    Thanks for creating a very useful app!

  45. Dominik says:

    Hi there,

    I'm having the same problem as Fyrtek… Please help!

    Thanks a lot,
    Dom

  46. Dominik says:

    Hi again,

    I got the plugin installed and connected to Twitter by now, but I'm now having the same problem Leandro describes in his June 05, 2011 comment below: The URLs are all messed up and I cannot figure out why.

    Any help will be greatly appreciated, thanks!

  47. Someone says:

    What's the PHP code we can add to single.php to show short link automatically on every post?

  48. Alex says:

    Hi,

    since WP 3.2 the option page don't show the option "New page published" any more.

    I search for the reason and I think I have it…

    Can you check my guess please an fix it if I'm right..?

    in the option.php you use this:

    $types = get_post_types( array('publicly_queryable' => 1 ), 'objects' );

    as input for the table loop.
    But Pages are not publicly_queryable and wordpress has fix this in 3.2:

    from source: http://codex.wordpress.org/Version_3.2:
    Fix mistaken use of publicly_queryable in when public was what was intended for register_post_type()

    Can you please review my guess?
    Thanks, Alex

  49. Alex says:

    Me again.
    found another hint:

    http://core.svn.wordpress.org/tags/3.2/wp-includes/post.php

    The default page type is register like this since wp3.2:

    register_post_type( 'page', array(
    […..]
    'publicly_queryable' => false,
    […..]

  50. Jamie says:

    Hey Ohz,

    I've installed WordPress to Twitter before without problems but this time I just can't get it right.

    When trying to add my Twitter details to the plugin, the details do not show up properly. The Callback URL is blank and the "in this help screen" link brings up the photo box but it's empty.

    I'm sure that if I got the Callback URL correct, this wouldn't be a problem! Any helpers?

    For reference, here's a pic of the settings page. The Callback URL is missing.

    http://disabledpeople.org/buttons/yourlsTwitterSettings.png

    Many thanks,

    Jamie.

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.