My tweet button submits are not shortening the submitting page's url


My tweet buttons have problems with the shortening urls. The code is shown below

On standard status update links, the link is not being shortened and is therefore exceeding the 140 characters. On submission, I am getting the “ops! Your tweet was over 140 characters.” message. Why is the shortener not working.

On type=“IN/Share” script for the button, the data-url is being ignored altogether. N link shortened or otherwise is displayed on the message UI.

The code used can be found here dev1.mycountdown dot org/test.html

My status update button

 <a style="text-decoration:none;margin:0px 0px;padding:0px 0px;text-decoration:none;" href=" days, 6 hours, 0 minutes until I am" alt="Share on Twitter" title="Share 118 days, 6 hours, 0 minutes until I am eighteen on twitter" rel="nofollow" target="_blank" class="twitter"><img border="none" src="/images/twitter-icon_small.png"></a>

My tweet count button

script type="IN/Share" data-url="" data-counter="top"></script></td><td><script src="" type="text/javascript"></script><span style="padding-left:0px;width:30px;padding-right:10px;vertical-align:bottom"><a href="" class="twitter-share-button" 
      data-counturl=" am eighteen&text2=Happy Birthday&group=Special Day&countdown=Birthday&widget_number=3010&event_time=1327536000" 
      data-text="118 days, 6 hours, 0 minutes until I am eighteen"


Few things here:

You’re mixing two APIs together with an additional antiquated mode of tweeting. The Tweet Button doesn’t use “IN/Share” script types, the LinkedIn API does though.

Your href for Tweeting isn’t well formed: days, 6 hours, 0 minutes until I am"

That’s an antiquated way to create a Tweet for a user, besides having some errors in encoding of the status and better ways to accomplish your goals.

Try using the Tweet Button/Tweet Intent’s distinct parameter for the URL and ensure you’re encoding characters like " " as “%20”.

As best as I can guess, you want something more like this for sharing on Twitter.


I am urlencode the message string and the url is now url=

Following your syntax I get no url at all.

check the right most twitter button


The URL you’re generating and passing to the Tweet Intent is still not encoded quite right – since the original URL has “+” characters in it, they need to be re-encoded when passing it as a URL parameter:

Should be:


Thanks for the comment.

I am puzzled, the url is straight output of the php urlencode() function…What do you use to encode urls?


Ah, just tested the html link button encoding spaces separately to urlencode, and the links are now being published. Curiously I am not getting a redirect, but the link is handled as a unit a single character long.

Even with the newly encoded url, the javascript twitter button in the middle of the page is still ignoring data-url links. The countup is working but not the link shortener. Cannot see what I am doing wrong there either…?

Thanks again for your help



Solved the problem

Basically twitter javascript requires custom url encoding, as follows

$countdown_url_encode = urlencode($countdown_url); $countdown_url_encode = str_replace("+","%2B", $countdown_url_encode); Works on the html twitter button

For the javascript button, the url must be further encoded as follows:

$countdown_url_encode = str_replace("%3F","?",$countdown_url_encode); $countdown_url_encode = str_replace("%2B","+",$countdown_url_encode); $countdown_url_encode = str_replace("%3A",":",$countdown_url_encode); $countdown_url_encode = str_replace("%2F","/",$countdown_url_encode); $countdown_url_encode = str_replace("%23","#",$countdown_url_encode);

best discussion thread is

closed #8