0

I'm trying to make a Custom Twitter Button in my content.php so where it's placed at the bottom of each post and a button appears that when clicked it can send a Tweet this to Twitter with the post id's url. However, I can't figure out this "bug" that I'm running into and I thought possibly one of you Stackoverflow Wordpress users would know.

So below is some code from my content.php and when I have just the a href link added the button works and can fetch the url. So when clicked on example it will go to twitter and have the url as myblog.com/mattspost-111. Do note that only the text shows and not the twitter bubble with how many tweets have been tweeted.

<span class="social"> <!-- Twitter --> <a href="http://twitter.com/home?status=Currently reading <?php the_permalink(); ?>"  class="twitter-share-button" data-via="MattStenquist" data-lang="en" data-size="large" data-related="MattStenquist">Tweet</a></div>

However, when I add the full code including Twitters < script >< /script > statement when the button is clicked all it does is pull up the url of the blog for example. myblog.com/blog not the post associated with it.

<span class="social">
<!-- Twitter -->
<a href="http://twitter.com/home?status=Currently reading <?php the_permalink(); ?>"  class="twitter-share-button" data-via="MattStenquist" data-lang="en" data-size="large" data-related="MattStenquist">Tweet</a>
<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="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
</div>

In short, all I want is so I can have a universal twitter button on the categories page that fetches the posts url, when in category mode and when in just viewing the post.

1

Well, you're missing several of the data bits. Notably, data-text and data-url.

See here for the parts of the tweet button code you should be including: https://dev.twitter.com/docs/tweet-button

0

You haven't used data-url field. Try this snippet and let me know if it works !

<a href="https://twitter.com/share" class="twitter-share-button" data-url="<?php the_permalink(); ?>" data-via="MattStenquist" data-lang="en">Tweet</a>
<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="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>​

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.