开发者

Twitter Status in wordpress and Tiny Url

开发者 https://www.devze.com 2023-03-12 19:00 出处:网络
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:

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 开发者_JS百科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!


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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号