Continuing my sem-series of posts that dissect some of what I’ve done on the recent redesign of ChurchCrunch, here’s how I auto-generate a TinyURL for each post automatically.
First, obviously, is why I do this. Here are some reasons:
- Some of my blog post titles are super long. Whoops. I want to be able to provide people with an easy-to copy URL for whatever purposes they might entertain.
- There are shorter services out there but none as well-known than TinyURL. I want to maximize potential clickthroughs for the people who use them by providing the most recognizable service.
- I copy and paste my links all the time. This helps do the work for me every single time without having to use a browser bar-addon or anything fancy like that.
- I thought it would be cool.
Here’s how you do it:
1. In your functions.php file in your theme template directory, add this code:
function getTinyUrl($url) {
$tinyurl = file_get_contents("http://tinyurl.com/api-create.php?url=".$url);
return $tinyurl;
}
2. Then in your single.php file or wherever the “loop” is, paste this
<?php $turl = getTinyUrl(get_permalink($post->ID)); echo '<a href="'.$turl.'">'.TinyURL.'</a>' ?>
Fun times!
[Completely random image from Bob]
Phillip Gibb says
nicce,
love this one and the email one earlier
JakeSchwein says
very cool…thanks
Jim says
super-ninja skills, thanks sensei!
Brian Alexander says
I have it on my main index page as well as my single index page. It looks like it's showing up, but I can't get the tiny url to actually generate. Take a look and give me some help if you can.
Brian Alexander says
Took it down, until I can figure out how to get it to work.
Paul Steinbrueck says
Why not use short URLs that are easier to generate, easier to remember, and help your branding?
https://churchm.ag?p=4891
human3rror says
Well, that's what I do too…!