WordPress Tutorial

How to Add Twitter Tweet Button to WordPress

Introduction

Twitter is one of the largest social media platforms. This tutorial shows you how to add Twitter button to WordPress website and allow your visitors to share content from your website to Twitter. We will be adding the tweet button on every post in WordPress.

[optin-monster-shortcode id="cgx87nzwxn0himxw62bn"]

What you’ll need

Before you begin this guide you’ll need the following:

Step 1 — Opening your post page template

Navigate to your WordPress Admin Area and open up Editor under Appearance:

Opening WordPress editor from appearance

After that, open up a template file for single posts. It is called single.php:

Open WordPress single post template file

Step 2 — Updating post template file

In your single.php file find a line <?php get_template_part( 'content', 'single' ); ?> and after it add the following code:

<script src="http://platform.twitter.com/widgets.js" type="text/javascript"></script> <a href="http://twitter.com/share?url=<?php echo urlencode(get_permalink($post->ID)); ?>&via=XXXXXX&count=horizontal" class="twitter-share-button">Tweet</a>

where XXXXXX is your Twitter username:

Modyfying the WordPress post template file

Don’t forget to save changes by clicking Update File.

Step 3 — Testing the Tweet button

Open up any post on your WordPress website and you will see a Twitter button at the end:

Testing Twitter button on wordpress

Conclusion

Now you know how to add a Twitter button to WordPress and it lets your visitors share your content. Just like a button can be added on posts, it can also be added on pages or in sidebar.

Join thousands of subscribers worldwide

and get awesome deals & the newest tutorials to your email

Please wait...

Thank you for sign up!

More in WordPress Tutorial
How to Add PHP Code to WordPress Post or Page

Close