YOURLS (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.
Download
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
Thanks so much for this awesome plugin.
You rock!!! ;-)
Hey I'm still writing the page :)
Ozh – your WP-reputation worth a thousand plugin tests!
"YOURLS: WordPress to Twitter" sounds great… I Trust in You :-)
Regards as always
Gianni
[…] Check out Ozh blog post on the WordPress plugin, YOURLS: WordPress To Twitter (a Short URL Plugin). […]
I must say this, this plugin is leet!
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
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
[…] YOURLS: WordPress to Twitter […]
Sorry. I have a problem, when I click "Tweet this", an error prompt is "Error during Ajax request: Internal Server Error".
9npc » Misconfiguration on your side. Can't help without more info
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.
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?
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!!!
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
Chuck » In next version I'll had a "Test connection" in the option page to check things
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.
The "blank edit screen" issue happens when YOURLS is used together with the "Twitter Tools" plugin. Deactivating either helps. Looking for a fix now.
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 );
break;
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!
Very awesome! already using it and it works like a charm.
thanks a lot :)
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
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:
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.
Nicolas
Wow, I like it, I will try it someday
[…] 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 […]
[…] Twitter ??????? API ????Ozh ????? Template Tags<?php if (function_exists('wp_ozh_yourls_url')) […]
Ozh–
Are you planning to add support for Su.pr to your already-awesome plugin?
Best,
Alex
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.
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.
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.
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
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
Thanks
Sujit » I'll have a look at ping.fm and their API
@ozh
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… :)
Cheers!!!
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!
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)
ORIGINAL FUNCTION ————
// 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";
}
ORIGINAL FUNCTION ————END
COPIED & MODIFIED FUNCTION ————
// Template tag: echo short URL only
function wp_ozh_yourls_urlonly() {
global $id;
$short = wp_ozh_yourls_geturl( $id );
if ($short)
echo "$short";
}
COPIED & MODIFIED FUNCTION————END
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.
[…] 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 […]
[…] http://planetozh.com/blog/yourls-wordpress-to-twitter-a-short-url-plugin/ […]
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):
Thanks for the awesome plugin!
Cheers
Stefan
Argh, lets try again :) To get the raw url use this code in your template (inside the loop):
hah – I KNEW there was probably a much simpler way of doing it. Thanks for sharing that!
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.
Jamie.
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.
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,
Jamie.
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
Now who feels stupid?!!!!
It's fixed – THANK YOU!
J.
[…] 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. […]
Wow, that is the best screenshot and description I've ever seen for ANY wordpress plugin. great job on this!
Shai » what? you mean you don't know my other plugins? :)
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?
mark beekman » running on dreamhost too. Check what is the Ajax response when you send the tweet, using Firebug on Firefox