Categories

Social media is everywhere and always changing. It is important to utilize social media in every way you can. One way is to boost your branding by having branded social media pages. Another is to use social sharing buttons. Recently, I worked on adding social sharing buttons on the Blueprint blog as a part of my front end development tasks. There are a variety of ways to add social sharing buttons in WordPress. Today I will be sharing how to add social sharing buttons manually to WordPress posts. This method is particularly useful if you really want to customize how the buttons look. You will have full control as to where you want the buttons to be placed on your blog post. To do this, we need to edit our WordPress theme. Specifically, we will be working in The Loop for single.php.

Adding Facebook Like button

You can generate and customize how a Like Button would look on the Facebook Developers website. For this tutorial, I have customized the code as how it looks on the Blueprint blog. The first code is the necessary JavaScript you need to put in your theme. Facebook recommends that it be placed right after the opening <body> tag.

For data-href, I put the WordPress template tag for getting the URL of the post. Because of the permalink template tag there, when you look at each blog post on the Blueprint blog, the URL you click like for is automatically generated as link for the blog post. Because we are putting the social sharing buttons in The Loop, we can use this template tag without problems.

The bottom portion is the JavaScript needed for the Twitter tweet button. As we did for Facebook Like button, we put the permalink template tag for data-url and the post title template tag for data-text. Remember that these template tags are only used in The Loop, so these tags would be appropriate in this case. Also, make sure to change BlueprintWebMedia to your Twitter handle so that when people click Tweet on your post on your website, they will mention the correct Twitter account. (If you would like, follow @BlueprintWebMedia!)

Adding Google+ share button

Google also offers a way to customize their Google+ button on the Google Developers site.

The above code is what I used for the Blueprint blog. Google recommends that the script be placed after the last +1 button on the website. Again, I placed the permalink template tag for data-href.

Conclusion

You could use the same codes for The Loop on index.php or wherever blog posts are displayed if you want. That is because we specified the URL to share in each code, so each button displayed on the blog posts page will have a different URL. If you did not specify the URL to share and you had the buttons on the blog posts page, you would have a bunch of share buttons that share the blog page (ex. yourdomain.com/blog) instead of the URL for individual posts. That is because each button defaults to the page URL that the button is placed if the URL is not specified. On the Blueprint blog, it is set so that only the excerpt shows instead of the full content, so it is appropriate to show the buttons only on the individual blog post. However you decide to do, I hope you found this article to be helpful!