(606) 654-4241 contact@taterkakes.com

AddThis boasts a powerful set of tools for social media sharing and traffic generation. I utilize their free Sharing Sidebar on the posts of this site (see left). There are a few WordPress plugins that help you enable some of the different tools, but I found that while useful that it usually enabled the sharing system for the entire website. In many cases that may be desirable, and in some cases not so much.

In my case, I preferred to only show my social media share icons (in the sidebar, floating, encouraging way) on my blog posts. I did not want to add the bar to my homepage especially.

I checked all the plugins and couldn’t find what I needed. So I came up with my own solution.

Add AddThis Sharing Sidebar to Only Posts (or any other criteria)

The first thing you will need to do is head over to http://www.addthis.com and create an account.

You’ll find the tool gallery and the free and pro sharing tools that are available. The one we are specifically working with is the free Sharing Sidebar.

You’ll have the opportunity to configure some settings, like weather to display the AddThis sharing sidebar on the left of the right, and at the end it will give you a snippet of code.

Screen Shot 2014-07-28 at 12.00.54 PM

AddThis gives you code, now what to do with it!

Since we’re only going to be showing the code on certain pages just copying and pasting the code into the header file won’t work. Not to mention that’s not really the best way to go about putting script into WordPress files.

We’re only going to need the information inside src=" " from the code we copied from AddThis.

You’ll need to open your functions.php file, you can find it in your child theme files (you do have a child theme right?), or if you don’t have one you can create one.

We’re going to add the following code:

What we have done is create a new function called show_share_buttons that adds the script to WordPress that we need for the social buttons to appear. Be sure to replace this-is-where-the-information-from-src-goes with all the information from between the quotation marks after  src= .

We use the add_action line to cause this script to run when WordPress is getting the headers (where we would normally be told to copy/paste the script).

The special line in this is the if ( is_single() ){ ... } .  For my case the is_single() conditional tag is exactly what I need. If the site is on a single post of any type except attachments and pages. This causes the function to only execute the wp_enqueue_script when it is only a single post.

You can change these conditions to suit your own needs.

But I want AddThis only on posts that are in ‘xyz’ category!

Use those conditional tags.

So we’re wanting to make sure it’s a single post AND that single post is in category ‘xyz’. Fair enough.

That’s it? Why should I bother?

Well you don’t have to bother. Or grab one of the many WordPress plugins that add sharing buttons for you with little to no effort involved. With the versatility that is WordPress we have plenty of options. If this happens to be exactly what you need, take a few minutes learn a little about some code and do it yourself, if not maybe I just introduced you to the awesome tools over at AddThis.