Create Your Own Twitter Share Button

As you can see on plugin page, there is a lot of Twitter share button which you can use, but all of them already valid, you cannot change their styling easily.

So, right now i will tell you how to create it with your own hands, sure you can do a styling on it.

<a href="<?php the_title(); ?>&url=<?php the_permalink();?>" target="_blank"><span>Twitter</span><i></i></a>

At that code, i using several CSS layers to make it more beautiful.

Then, to displaying the counter of how many url shared, you can open your functions.php or theme-functions.php and put this code:

function get_tweets($url) {
 $json_string = file_get_contents('' . $url);
 $json = json_decode($json_string, true);
 return intval( $json['count'] );

Then, to call the counter, you can simply put this code at your page.php or single.php:

<?php echo get_tweets(get_permalink($post->ID)); ?>

Done! You already create your own Twitter button



5 thoughts on “Create Your Own Twitter Share Button

  1. This can be actually serious, You’re an incredibly efficient writer. I’ve joined with your feed and also will enjoy finding your outstanding write-ups. In addition, I’ve shared your blog post with our social networking sites.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s