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
- Copy it into the
wp-content/pluginsdirectory 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.
/bl/to any other that you want. Just remember to keep the slashes at the beginning and the end of the string.
$textto whichever template you want to use to print your tiny url. Just remember, to use
%swherever you want the tiny url to be substituted. If you use
%smore or less than twice, remember to change the first
printffunction in the code accordingly.
- As an added feature, if you set the variable
Truein the code, the code will also provide you with the
.htaccessrule 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
.htaccessfile in your domain web root. You can set this variable to false after you have configured your
That’s it.comments powered by Disqus