0815

Du musst dich anmelden um Beiträge und Themen zu erstellen. Einloggen · Registrieren

Display Automatic TinyURLs for Your Posts

Make it super-easy for your visitors to share the URL of your posts with their favorite social-media service. Providing an alternate “short” version of your URLs is possible using the free TinyURL service and a couple snippets of code.

To display short URLs at the end of your posts, place this code into your theme’s functions.phpfile:

function getTinyUrl($url) {
	$tinyurl = file_get_contents("http://tinyurl.com/api-create.php?url=".$url);
	return $tinyurl;
}

Then, call the function and display the URL by placing this code into your single.php file in the desired location within the loop:

<?php $turl = getTinyUrl(get_permalink($post->ID)); 
echo 'TinyURL for this post: <a href="'.$turl.'">'.$turl.'</a>'; ?>

That’s it! Your posts now feature super-short URLs for all of your tweet-hungry visitors.




0