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 regarding TinyURL. 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 by Andy Wibbels and created a real small plugin, to display the “tiny url” in your post.
To use it:
- Download it from here.
- Rename it to
wptinyurl.php
. - Copy it into the
wp-content/plugins
directory in your WP root. - Activate the plugin in your WP admin section.
- Then use the function
wptinyurl()
in your template files, wherever you want the tinyurl of the post to be displayed.
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.
- 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. - 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 firstprintf
function in the code accordingly. - As an added feature, if you set the variable
$print_rule
toTrue
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.
comments powered by Disqus