The new
BackType Tweetcount just launched last night. With a little work, it’ll support your very own custom shortened URL in the re-tweet. We like
su.pr. Thanks to a bit of help from
Michael of BackType, we’re able to figure out this mod overnight.
The previous version of BackType worked well but it always re-tweet your posts through
awe.sm. That’s great and all, but what about the rest of us who have our own click tracking or even our own custom shorteners.

So to make it better, last night we added a new option for developers to add a function into the code that will allow them to build their own custom functions and generate their own custom links. It’s really just a meta tag, “
bttc_short_url” that gets generated the first time the post is viewed. Here’s the best part. Since the short url is generated the FIRST time everything is viewed. Just by browsing your pages, and olf non-syndicated links are automatically added into su.pr. If you use another shortening service, it’ll do the same for that too.
After grabbing the latest BackType Tweetcount, load up your favorite editing tool and add this function to the very bottom of the code:
| 01 |
|
| 02 | function bttc_supr($url) {
|
| 03 | $SU_username = "username";
|
| 04 | $SU_api = "api_key";
|
| 05 | $SU_url = "http://su.pr/api";
|
| 06 | $SU_vars = "?url=$url&login=$SU_username&apiKey=$SU_api";
|
| 07 | |
| 08 | $curl_handle = curl_init();
|
| 09 | curl_setopt($curl_handle, CURLOPT_URL, $SU_url . $SU_vars);
|
| 10 | curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
|
| 11 | curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
|
| 12 | curl_setopt($curl_handle, CURLOPT_HTTPGET, 1);
|
| 13 | $buffer = curl_exec($curl_handle);
|
| 14 | curl_close($curl_handle);
|
| 15 | //$SU_newURL = str_replace("su.pr/", "", $buffer);
|
| 16 | $SU_newURL = $buffer;
|
| 17 | |
| 18 | return $SU_newURL;
|
| 19 | }
|
| 20 | |
As a quick note there. The commented out
//$SU_newurl is for those that host their own url shortcodes on their domain using the su.pr htaccess modification.
Go to Line 180, insert this code:
| 1 |
|
| 2 | if (get_post_meta($post->ID, 'bttc_short_url', true) != '') {
|
| 3 | $button .= 'tweetcount_short_url=\'' . wp_specialchars(get_post_meta($post->ID, 'bttc_short_url', true), '1') . '\';';
|
| 4 | }
|
| 5 | |
Then go to Line 161, search for this code:
| 1 |
|
| 2 | if ($meta == '') {
|
| 3 | add_post_meta($post->ID, 'bttc_cache', time() . ':' . $cnt);
|
| 4 | } else {
|
| 5 | update_post_meta($post->ID, 'bttc_cache', time() . ':' . $cnt);
|
| 6 | }
|
| 7 | |
Directly below the code, paste the following:
| 1 |
|
| 2 | if (get_post_meta($post->ID, 'bttc_short_url', true) == '') {
|
| 3 | $short_url = bttc_supr($url);
|
| 4 | if ($short_url) {
|
| 5 | add_post_meta($post->ID, 'bttc_short_url', $short_url);
|
| 6 | }
|
| 7 | }
|
| 8 | |
And that's it. Edit the first bttc_supr function into basically whatever you want, and the short URL will automatically generated the first time the posts are viewed. It'll let you re-tweet with your own custom links, and even add old content that you haven't added to your shortening admin pages for you. This is a pretty raw version of doing this. BackType will be launching an updated version soon with these modifications to make it easier for users that don't want to edit as much code.
Was this useful? Help share it: