Code Lover
Code Lover

Reputation: 8348

Twitter auto shorten URL not working

I am trying to add custom tweet button to my website and all is well but it is not shortening the URL. I am using URL query string instead of javascript. Is that the case?

<a class="btn btn-tweet" target="_blank" href="https://twitter.com/share?text='.$title.'&url='.$url.'&via='.$user.'&wrap_links=true">Twitter</a>

I have read some API document and saying above 19 characters twitter shorten url itself. Just wonder why it is not converting with this.

I am also having trouble to open in popup instead of new window. Does this all possible without adding any separate javascript code but directly inline in anchor tag?

Upvotes: 5

Views: 7574

Answers (2)

James Gentes
James Gentes

Reputation: 8086

I was hung up on this and realized I was trying to shorten "http://localhost:5000/blog/url" which t.co is unable to do.

Change to a real, non-localhost URL and it worked fine.

Upvotes: 22

ceejayoz
ceejayoz

Reputation: 180014

It won't be visibly shortened in the compose window, but the compose window does detect URLs and adjusts the character count accordingly. Try pasting a huge long URL - it'll only use up 22 characters in the count.

Do note that Twitter shortens all URLs, even when "shortening" actually makes them longer. For example, "http://bit.ly" will use up 22 characters (not 19), not 13.

Upvotes: 8

Related Questions