Question

I have a wordpress site. I have a twitter button below every post. What I want is that when a user clicks on it, it should update their twitter status to the following:

the_title().urlencode(get_permalink()) [first the title of the post on which the user clicked the twitter button followed by the url of the post]

mow my problem is that the output from urlencode(get_permalink()) is very large and in the twitter status it displays just plain text not the hyperlink as is expected. Somewhere i read about tiny url. But what should be the code to pass my url to tiny url and get the shortened version of it so that the hyperlink is active in my twitter status.

Thanks in advance!

Was it helpful?

Solution

I found the solution. Thanks if you spent time to view this. Thought to post the answer just in case anyone else faces similar situation

function get_tiny_url($url) { 
    $ch = curl_init();
    $timeout = 5;
    curl_setopt($ch,CURLOPT_URL,'tinyurl.com/api-create.php?url='.$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top