X

Create tiny URLs automatically

Add the first section of code into your functions.php. Adding the second section of code into your single.php template file will automatically create and display the tiny url.


function getTinyUrl($url) {
    $tinyurl = file_get_contents("http://tinyurl.com/api-create.php?url=".$url);
    return $tinyurl;
}
<?php
$turl = getTinyUrl(get_permalink($post->ID));
echo 'Tiny Url for this post: <a href="'.$turl.'">'.$turl.'</a>'
?>

Comments  Leave a Reply

  1. Tweets that mention Wordpress Create tiny URLs automatically – wpsnipp.com Wordpress code snippets for your blog -- Topsy.com November 4, 2010 at 7:47 pm

    […] This post was mentioned on Twitter by Zlata, Natella and MíriamDePaula-Drika, WPSNIPP. WPSNIPP said: #wordpress Create tiny URLs automatically http://bit.ly/9QGPWE #tips #help #blog […]

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!