01. Create TinyURLs On The Fly
The problem. Because Twitter has become a social media revolution, many bloggers and Twitter users enjoy sharing blog posts they have found and liked on Twitter. However, manually creating a TinyURL before tweeting can get a little tedious. As you probably know, Twitter can bring a lot of traffic to your blog, so it is in your interest to consistently provide short URLs to your readers.
The solution. To use this recipe, follow the simple steps below:
- Open your functions.php file.
- Paste the following code in the file:
function getTinyUrl($url) { $tinyurl = file_get_contents("http://tinyurl.com/api-create.php?url=".$url); return $tinyurl; } - Open your single.php file and paste the following in the loop:
ID)); echo 'Tiny Url for this post: <a href="'.$turl.'">'.$turl.'</a>' ?>
- That’s all you need. Each of your posts now has its own TinyURL, ready for tweeting!
Code explanation. The popular URL shortening service TinyURL provides a quick API that creates TinyURLs on the fly. When you pass a URL to
the API immediately prints the related TinyURL on the screen.
Using the PHP function file_get_contents(), we can get it and assign it to the $tinyurl variable. The last part of the code retrieves the post’s permalink and passes it as a parameter to the getTinyUrl() function previously created.
Source:
02. List Upcoming Posts
The problem. If you often schedule posts to be published, how about displaying them in a list? This will make your readers look forward to what you’re going to publish in a few days and can help you reach new RSS subscribers. Implementing this functionality on your WordPress blog isn’t hard at all.
The solution. Nothing hard here. Just copy this code and paste it anywhere in your theme files.
<div id="zukunft"> <div id="zukunft_header"> Future events </div> <div> <b></b> <span class="datetime"></span> </div> No future events scheduled. </div>
Once you’ve saved the file, your upcoming posts will be displayed on your blog.
Code explanation. This code use the super-powerful query_posts() WordPress function, which allows you to take control of the WordPress loop.
The parameter used is post_status, which allows you to get posts according to their status (published, draft, pending or future). The showposts parameter is also used to define how many items you’d like to get. You can change the value of this parameter on line 4 to retrieve more or less than ten posts.
Source:
03. Create A “Send To Facebook” Button
The problem. In the first hack, we noted that Twitter can bring a lot traffic to your blog. Another website that can boost your traffic stats easily is Facebook. In this hack, let’s see how we can create a “Send to Facebook” button for your WordPress blog.
The solution.
- Open the single.php file in your theme.
- Paste the following code in the loop:
<a href="http://www.facebook.com/sharer.php?u=&t=" target="blank">Share on Facebook
- Alternatively, you could use the getTinyUrl() function to send a short URL to Facebook:
ID)); ?> <a href="http://www.facebook.com/sharer.php?u=&t=" target="blank">Share on Facebook
- That’s all. Your readers will now be able to share your blog post on Facebook with their friends!
Code explanation. This useful hack is very easy to understand: the only thing we do here is retrieve the post’s permalink and title and send them as parameters to
In the alternative method, we used the getTinyUrl() function (created in the previous hack) to send a short URL instead of the post’s permalink.
Source:










