Taher
Taher

Reputation: 12050

Twitter's share ignores my data-url and data-text

Whatever I set data-url or data-text to, twitter just fetches the URL of the page the sharing button exists in and shows as the tweet-text.

example :

<a target="_blank" href="https://twitter.com/share" 
data-count="none" class="twitter-share-button" data-url="http://www.gogole.com" 
data-text="BLABLABLA" style="opacity:0">TWEET</a>

or

<a target="_blank" href="https://twitter.com/share" 
data-count="none" class="twitter-share-button" data-url="<?php echo 
urlencode('http://www.gogole.com')?>" data-text="BLABLABLA" style="opacity:0">TWEET</a>

in both cases, clicking on the link opens a new window with the twitter sharing box that includes the URL of my website and ignores the attributes I set.

Something should have gone dangly wrong. help appreciated ! please tell me if you need more info to be posted.

Thanks, /t

Upvotes: 3

Views: 3851

Answers (3)

Fedor Cherepanov
Fedor Cherepanov

Reputation: 198

I fixed this by moving script widgets.js before button markup and turning off async mode, like this:

<script src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
<a href="https://twitter.com/share?ref_src=twsrc%5Etfw" class="twitter-share-button" data-text="H..." />

twitter-share-button class also important.

Upvotes: 1

Sergey  Fedirko
Sergey Fedirko

Reputation: 659

I have faced same issue - when using link as described in manual's example it didnt work.

this NOT works:

<a class="twitterBtn smGlobalBtn" target=_blank href="https://twitter.com/share" data-text="my_title" data-url="my_url" data-hashtags="my_hash" data-via="my_name" data-related="my_name">Tweet</a>

but this WORKS:

<a class="twitterBtn smGlobalBtn" target=_blank href="https://twitter.com/share?text=my_text&url=my_url&hashtags=my_hash&via=my_name&related=my_name">Tweet</a>

Don't know why twitter ignores data- attributes, but when params are inside the link as GET params - everything works fine.

Hope this will be helpful for someone in future)

Upvotes: 2

Veer
Veer

Reputation: 371

You can use the query parameter "url" with the twitter share link "https://twitter.com/share" When looking for the URL twitter button follow this priority:

  1. Look for url in the share link query string
  2. If not found, look for the data-url attribute of the Tweet Button anchor tag
  3. If not found, look for the rel="canonical" link tag in the head of the document
  4. If not found use the URL of the webpage

Upvotes: 3

Related Questions