Reputation: 1707
I'm trying to embed a tweet button in my page that tweets a dynamically generated url.
I've gotten the button to tweet the full url, but in the interest of minimizing characters in the tweet, I'd like to strip out the http://www
. However, when I attempt assign this to the data-url attribute of the twitter button anchor tag, the url does not appear in the tweet.
Thus, $url = 'http://www.mypage.com/?id=2'
works $url = 'mypage.com/?id=2'
does not.
I'm using the js api and my implementation is as follows:
<a href="https://twitter.com/share" data-url="<?php echo $url;?>" class="twitter-share-button" data-text="test copy" data-lang="en">Tweet</a>
plus twitter's js:
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="https://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
I can see why http stuff would be necessary to broaden the url scope, but in the interest of serving their main customer base, I would think twitter might have a way of making this info implicit. Is there something I can add that tells twitter, 'interpret this as http://www.blahblahblah...'?
Upvotes: 0
Views: 829
Reputation: 1707
Setting thedata-url=" "
and data-text= <my url>
works fine, and apparently twitter knows to make urls in data-text into anchor tags. Not technically an answer but functionally the same as far as I can tell
Upvotes: 1
Reputation: 14464
Try $url = '//mypage.com/?id=2'
. It's called a protocol-relative URL. Might work.
Upvotes: 1