WordPress tinyurl plugin

I was in a quandary. I wanted the long permalinks for my blog posts,which made links self-describing and also search engine friendly. And I also wanted short URLs that I could pass on in emails. I share [the sentiments of Andy Wibbels][1] regarding [TinyURL][2]. Nothing against TinyURL personally, just that when you have your own domain name for your blog, wouldn’t you prefer using tiny urls using your own domain name?

So I extended the [one liner][1] by Andy Wibbels and created a real small plugin, to display the “tiny url” in your post.

[1]: http://easybakeweblogs.com/2005/01/20/i-hate-tinyurl/
[2]: http://www.tinyurl.com/

To use it:

1. Download it from [here][3].
2. Rename it to `wptinyurl.php`.
3. Copy it into the `wp-content/plugins` directory in your WP root.
4. Activate the plugin in your WP admin section.
5. Then use the function `wptinyurl()` in your template files, wherever you want the tinyurl of the post to be displayed.

[3]: http://www.sandipb.net/downloads/wptinyurl.txt

In my case, to display the tiny urls in my posts, I have added the following line just before `edit_post_link()` in the `single.php` file in the theme directory. The relevant section of the file in my case now looks like this:

By default, the code uses the prefix `/bl/` for generating your tinyurls. So your typical tinyurls will be `http://yourdomain/bl/nn`, where nn is your post id.

To customize, edit the `wptinyurl.php` file, and change the variables as commented.

1. Change `$prefix` from `/bl/` to any other that you want. Just remember to keep the slashes at the beginning and the end of the string.
2. Change `$text` to whichever template you want to use to print your tiny url. Just remember, to use `%s` wherever you want the tiny url to be substituted. If you use `%s` more or less than twice, remember to change the first `printf` function in the code accordingly.
3. As an added feature, if you set the variable `$print_rule` to `True` in the code, the code will also provide you with the `.htaccess` rule that you require to make the tinyurl work. The rule will be inside an HTML comment. You can simply copy-paste from the HTML source of the page and add it at the end of the `.htaccess` file in your domain web root. You can set this variable to false after you have configured your `.htaccess` file.

That’s it.

This entry was posted in Uncategorized and tagged . Bookmark the permalink.
  • http://www.srijith.net/trinetre/ Srijith

    Nice plugin. Just out of curiosity, can the “$prefix” be removed completely? If I have WP installed at the root of the public_html, I’ll rather have http://yourdomain/nn as my TinyURL.

  • http://www.srijith.net/trinetre/ Srijith

    Nice plugin. Just out of curiosity, can the “$prefix” be removed completely? If I have WP installed at the root of the public_html, I’ll rather have http://yourdomain/nn as my TinyURL.

  • http://www.sandipb.net/ Sandip Bhattacharya

    Sure. Just set $prefix to /. However, dont set $print_rule to generate the .htaccess rule, because it would break for such prefixes.

  • http://www.sandipb.net Sandip Bhattacharya

    Sure. Just set $prefix to /. However, dont set $print_rule to generate the .htaccess rule, because it would break for such prefixes.

  • http://giantmonster.com/?p=30 giantmonster » Blog Archive » wpTinyUrl no workie …

    [...] dag-nabbit! i can’t get the wpTinyUrl plugin to work now. it handled everything fine at first. but since changing the permalink structure, it doesn’t work. oh well. mor eto learn … [...]

  • http://www.madeena360.com/ Waleed Nassar

    Your plugin is what I need and I installed it with no problems. But the tinyurls written are not loading the specific post. Take a look at my website- http://www.madeena360.com/.
    I want to add that my wordpress theme, based on Minima Plus, does not have a single.php file, so i added the code to my main index page. Is that the problem? Thanks.

  • http://www.madeena360.com/ Waleed Nassar

    Your plugin is what I need and I installed it with no problems. But the tinyurls written are not loading the specific post. Take a look at my website- http://www.madeena360.com/.

    I want to add that my wordpress theme, based on Minima Plus, does not have a single.php file, so i added the code to my main index page. Is that the problem? Thanks.

  • http://gameburn.org/ Sawyer

    Can anyone give me ideas , i might get free time in the future and want to give it for wordpress …
    any idea ?
    i want idea from simple thing to mid … 1-2 hours –> 8-10 hours .
    post your ideas…

  • http://gameburn.org Sawyer

    Can anyone give me ideas , i might get free time in the future and want to give it for wordpress …
    any idea ?
    i want idea from simple thing to mid … 1-2 hours –> 8-10 hours .
    post your ideas…

  • http://geraldlevert.blogs.ie/ Jaylon

    Does anyone know the name of the wordpress plugin that creates a list of your posts in a category instead of just displaying them one after the other? I want it so that when someone clicks on a category they just get a list of posts from that category.
    I'm sure Ive seen one…and sifting through the WP site is a nightmare

  • http://geraldlevert.blogs.ie Jaylon

    Does anyone know the name of the wordpress plugin that creates a list of your posts in a category instead of just displaying them one after the other? I want it so that when someone clicks on a category they just get a list of posts from that category.

    I'm sure Ive seen one…and sifting through the WP site is a nightmare

blog comments powered by Disqus