Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

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

share|improve this answer
add comment

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>​
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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