Beginner's Guide for WordPress / Start your WordPress Blog in minutes

How to Add Twitter Share and Retweet Button in WordPress

Do you want to add Twitter share and retweet buttons to your WordPress site?

Adding social sharing buttons to your WordPress posts and pages is a great way to encourage readers to share your content with their followers.

In this article, we will show you how to add a Twitter share and retweet button to all of your posts, so your audience can tweet your stories with one click.

How to Add Twitter Share and Retweet Button in WordPress

Why Add Twitter Share and Retweet Button in WordPress?

People spend a lot of time on social media sites like Twitter every day. That’s why social media marketing is one of the most effective ways to bring new users to your WordPress blog.

The problem is that when you share your content on social media, it only reaches a limited number of your own followers.

A smart way to reach people who don’t follow your business on social media is by adding a Twitter share and retweet button to your WordPress site.

A tweet button will prompt your website visitors to share your content on their Twitter timeline. It will then be seen by their friends and followers who can add comments, like, and retweet it.

They may also follow you on Twitter and visit your website. The extra exposure could also generate leads and sales and build social proof and brand recognition.

That being said, let’s take a look at how easy it is to add a Twitter share and retweet button in WordPress.

How to Add Twitter Share and Retweet Button in WordPress

For this tutorial, we’ll be using the Shared Counts plugin. It is the best WordPress social media plugin available on the market.

It lets you easily add social share buttons for Twitter and other platforms in your WordPress posts, and can also display how many times each post has been shared. The best part is that it is optimized for performance and doesn’t slow down your website.

Unlike other social sharing plugins, Shared Counts uses a unique caching method to have minimal impact on your website’s speed and performance.

We’ll start by installing and activating the Shared Counts plugin. If you’re not sure how, then see our step by step guide on how to install a WordPress plugin.

Upon activation, a ‘Shared Counts’ section is added to your dashboard. You need to go to the Settings » Shared Counts page to choose which social share buttons you want to display.

Shared Counts Settings Page

Once you get there, you need to scroll down to the ‘Display’ section and make sure that the Twitter share button will be displayed. Notice that Facebook, Twitter, and Pinterest buttons are already selected.

Select Which Social Buttons Are Displayed

If you want to delete one of the buttons, then just click on x on the right side of that button. To learn how to add share buttons for more social channels, check our guide on how to add social share buttons in WordPress.

You’ll also need to choose which button style to use. Once you click the dropdown menu labeled ‘Share Button Style’ you’ll notice there are 8 styles to choose from.

You can preview the styles by clicking the ‘plugin page’ link and select the one that best suits your website.

Select Which Button Style to Use

Now we’re ready to select the location where the Twitter share button will be displayed. The ‘Theme Location’ dropdown lets you place it in one of three locations: Before Content, After Content, and Before and After Content.

Select Where the Button Should Appear

Lastly, you need to select the supported post types. By default, the button will appear on all of your posts. If you want to display share buttons on your pages and other post types, then you can check the box next to the page option.

Select the Supported Post Types

Don’t forget to click on the ‘Save Changes’ button at the bottom of the page to store your settings.

We’re all done. If you want to see the Twitter share button in action, then simply visit any post on your website. Here’s how our demo website looks with the ‘Classic’ button style.

Sample Tweet Button with Classic Style

We hope this article helped you learn how to add social share buttons in WordPress. You may also want to learn the best way to create an email newsletter, or see our comparison of the best email marketing services.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit – a collection of WordPress related products and resources that every professional should have!

Reader Interactions

38 CommentsLeave a Reply

  1. Thanks for the quick response. I’m not a programmer, do you know where I can get a peice of code and paste it in? Re: Count, I’m thinking then that when testing, If I use the tweet button to post to post to my own page, then twitter doesn’t tink it’s legit? However, I have another twitter acc’t that I tried tweeting to and it didn’t increase. Is there a way I can test it to see that it’s working? How do I know it’s a legit tweet or not? I’m surpirsed that Twitter seems difficult compared to FB @wpbeginner

  2. @RandyDueck Twitter uses the new t.co shortner which only shorten links for their algorithm to make sure it is not SPAM… then it pastes the unshortened version… You have to utilize another API and write a bit of custom code to get the custom short URLs to work there…As far as the count, twitter button only shows count that it thinks are legit.

  3. Thanks for this great little code snippet. I want the twitter button to be in the post excerpt and below the title of the single-post page. the code works fine. gives the correct title etc. however, it does not shorten the link, and after tweeting, the tweet count doesn’t go up. the site is thinkactloveloseweight.com Thank your response

  4. Gretchen – all links should trace back to your permalink – so your permalink should be the source URL, not your short link … make sense? YOu can’t yet change the URL shortener if you use the official Tweet button ( I looked into it because I wanted to do a shortlink).

    Adding this so long after the original was posted because others might have that question!

  5. I thought I would note that some themes change the value for the title and post url – meaning that the code will tweet with your code in quotes. I got a couple questions on Twitter over that one. I just found the different variables that worked for my site and replaced them. So …

    Line three: data-url=””

    was changed to %permalink% – which was my theme’s replacement

    Line five: data-text=””

    was changed to %post-title% – again my theme’s replacement

    I wouldn’t have been able to do this without your tutorial! Thanks SOOOO much! You are now my go-to resource!

  6. @wpbeginner @idowebmarketing Okay, there are two locations of this code, and I had only updated one!

  7. @idowebmarketing @wpbeginner data-via is the only thing that needs to be modified in order to make the change.

  8. @wpbeginner @idowebmarketing Thanks – I added new blog posts to two of my blogs yesterday after implementing the updated code, however it still recommended wpbeginner on both. Is there any section of code that also needs to be updated?

  9. @idowebmarketing On old posts it takes twitter while to figure it out. On new posts it should be fine.

  10. My blog is still recommending wpbeginner and I have updated the code. Here is the edited code:

    <script src=”http://platform.twitter.com/widgets.js” type=”text/javascript”></script> <a href=”http://twitter.com/share” data-url=”<?php the_permalink(); ?>” data-via=”idowebmarketing” data-text=”<?php the_title(); ?>” data-related=”imnewsdaily:Daily updates from the internet marketing industry” data-count=”vertical”>Tweet</a>Any idea what I am doing wrong?

  11. Thank you for posting this!! I have been trying to slove this problem for about three days now…

    do you have the same code for the facebook like button?

  12. I use the WP-generated shortlinks when tweeting about my posts, and have had troubles with those always showing in my Tweet count. The final bit of code on this site seems to work, though if you click to view the search results in Twitter it only shows the links to the actual permalink, not the links to the shortlink as well: http://bavotasan.com/tutorials/adding-tweet-button-wordpress/ It’s too bad WordPress and Twitter don’t count those as the same link somehow…

  13. I can add javascript in header but it will degrade YSlow rating, currently it is B rating. I really work hard to make B from D. I opened a ticket to twitter technical team, they just sent me email providing some links which may help me to get my answer or open a new ticket if not. Thats so stupid. Twitter people think we didn’t see other answers! thats so frustating. Linkedin doing quite well , their share button updates within a minute.

  14. In my above mentioned website, i used your code, index.php, single.php and other php file within loop.
    I can click the twitter tweet button and it shows count number, but if i refresh the page, that value goes away. Now after may be 1 hour if i check that article page, i can see the new count value. e.g. before i clicked the button it was 0, after almost 1 hour it shows 1. My question is why it took 1 hour to update. it should be updated immediately isn’t it?

    Now in front page which index.php, i used the code and again i used in single.php. User clicks an article from index.php and comes article page which is in single.php. The problem: count value is not synchronising the count from the index.php to single.php. I check it later it is but after almost 1 hour. so it is synchronising after almost 1 hour.

    Why? any idea.

    Recently I changed the .htaccess file to add expire headers to get some speed. i am getting that but today i removed that line and back to default .htaccess file. Do you think its something with .htaccess where caching is controlled by hour, minutes, seconds, months or even year. Even though if I enable caching, the twitter java script which is twitter server can’t force to use caching.

    Now I am not sure where I should look for to get immediate count value. client wants to see immediate count and synchronise with article page.

    Please check the http://www.bizgene.com to get an idea.

    Any clue or idea will be a great favour.

    I used following code for tweet count button:

    <a href="http://twitter.com/share&quot; class="twitter-share-button"
    data-url="”
    data-via=”bizgene”
    data-text=””
    data-count=”horizontal”>Tweet

    Zakir

    • Zakir, We think this is a common bug going on with twitter API. We have been noticing a similar thing with our tweetmeme button regarding the count. It synchornizes the count almost after 20 – 30 minutes. Perhaps try adding the script part in your head codes and then display the a href part where you want the button to display might help.

      Admin

  15. I don’t get it. Using the data url link/button above gives just a t.co link and nothing else. Has something changed there or why doesn’t it output the values?

    • Note, to get the_title(); or the_permalink(); you have to place this code inside the loop. If you place it outside a loop, then it will not give you a desired value.

      Admin

  16. ARGH. This is what I tried but im replacing the greater-than/less-than symbols with brackets so it will hopefully show:

    [?php the_title(); ?] #[?php the_category(‘,’); ?]

  17. um… last comment isn’t displaying the php… sorry. This is what i tried: (hopefully this will work)
    #

  18. For DataText, im looking to add the title and category of the post as a hashtag. I can’t seem to figure out how to do it, being that I’m not too familiar with php.

    I tried: >>> data-text=” #”

    but that didn’t work. Any idea of how to do this?

  19. There isn’t much sense in filling out every setting, most of them work just fine without being set and will pick things like current URL and page title by default.

    Non-standard tag attributes will not validate (at least not as XHTML Transitional in my experience so far). Query arguments may not look as tidy, but they are more established and reliable.

  20. Is there any chance I don’t have “The Loop” because I keep looking for this (or even a part of it) in my index file and it’s not there. Gah, I was hoping this would be easy! :-(

  21. I used to have Topsy buttons… was about to switch for the official button but… It seems this version have a problem recognizing the real count of tweets. I had a post of 52 tweets and now it shows 8.

Leave a Reply to jafar Cancel reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.