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.
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.
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.
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.
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.
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.
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.
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.
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
@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.
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
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!
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!
@wpbeginner @idowebmarketing Okay, there are two locations of this code, and I had only updated one!
@idowebmarketing @wpbeginner data-via is the only thing that needs to be modified in order to make the change.
@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?
@idowebmarketing On old posts it takes twitter while to figure it out. On new posts it should be fine.
My blog is still recommending wpbeginner and I have updated the code. Here is the edited code:
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?
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…
hello sir sir how do i use this for pages ? i was able to do it for posts
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" class="twitter-share-button"
Editorial Staff says
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.
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?
Editorial Staff says
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.
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(‘,’); ?]
um… last comment isn’t displaying the php… sorry. This is what i tried: (hopefully this will work)
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?
S.Pradeep Kumar says
Nice tutorial. Finally I implemented that button on my blog. It will be nice if you can make a tutorial on how to customize it. I hate the default color. : |
Calítoe.:. (Cristina MJ) says
I’ve noticed that the count displays horizontally even if one specifies data-count=”vertical”. Does anyone know what’s wrong with that?
I’m having the exact same problem. Any idea how to fix it?
Editorial Staff says
Refresh the page… This usually happens when the twitter script is not loading fine. Try placing the twitter script part in the head section.
I think I’ll stick to the tweetmeme version until the plugin is completely developed with all of the options for placement.
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.
Alternatively, you could use WordPress’ very own add_query_arg() function, to create the url.
Nice post though, and quick, too.
Editorial Staff says
Yup, we had to put it out quick because a lot of our twitter users said they wanted it.
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!
Editorial Staff says
That really depends on what theme you are using. Every theme must have the loop to show the recent posts. You can try Otto’s plugin.
DJ NightLife says
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.
They’re only counting tweets since July.
BTW, the new tweet button is fully supported by my Simple Twitter Connect plugin for WordPress. Just so you know.
Editorial Staff says
Thanks Otto for updating your plugin. Your work is truly awesome Jut added the link in the post.
Ted Thompson says
Helpful article, many thanks!
Excellent, thanx !
Any chance to include custom url shorteners, such as cli.gs or bit.ly ?
Editorial Staff says
No, twitter is using their very own service to verify the quality of link that is being tweeted.