Blog

Using the AddThis WordPress Plugin with Custom Post Types

by

AddThis is super handy free service that allows you to integrate sharing tools on your website, allowing you to spread content, and drive social traffic.

That’s pretty much what they say on their website anyway, and I have to agree. The AddThis Social Bookmarking Widget allows any visitor to bookmark and share your site easily with over 330 popular services.

The main purpose of AddThis is to make it easier for you to add the pretty little social buttons on your website or blog. Sure, you can add each separately yourself, which may give you more control (hooray!), but it will also take more of your time (clients say “boo!”).

There is a very easy to use WordPress plugin on offer (appropriately named AddThis), and it’s pretty good. Once activated it automagically inserts lines of social bookmarking buttons (Facebook Like, Google +1, Twitter etc.) at the top and/or bottom of your content in various styling options. There’s a nice administration area that appears in your Admin area under the Settings menu where you can fiddle with settings and what-not, but problem is (as I recently found out) it doesn’t play that well with Custom Post Types. You can play with the options to hide/show it for categories, the homepage, excerpts etc., however there’s no simple way to turn AddThis button sets on/off for different Post Types. It’s all or nothing.

The solution

Fortunately there is a solution, and it comes by way of the ‘addthis_post_exclude‘ filter. You can interact with the filter in your functions.php file and hey presto!

The following example allows you to turn off AddThis for Custom Post Types, but there are many other uses of course.

<?php
//Exclude AddThis widgets from anything other than posts
add_filter('addthis_post_exclude', 'addthis_post_exclude');
function addthis_post_exclude($display) {
  if ( !is_singular( 'post' ) )
    $display = false;
  return $display;
}
?>

Updated:

10 response to Using the AddThis WordPress Plugin with Custom Post Types

  1. what you’ve said makes sense, and i can understand it very clearly, thanks.

    » Reply

  2. hey, i like your valuable article in which you have described very well with point wise.

    » Reply

  3. we all know why this site is so useful. congrats!!

    » Reply

  4. really cool website. i loved it.

    » Reply

  5. very interesting stuff.

    » Reply

  6. how exciting! i have really enjoyed reading this post. you guys have built a great community!

    » Reply

  7. nice, thanks for providing us with this information.

    » Reply

  8. Thanks for sharing your code. It helped me get the results I wanted.

    Instead of checking ( ! is_singular( ‘post’ ) ), you could check for ( ‘post’ != get_post_type() && ‘page’ != get_post_type() ). This way we can show AddThis on posts and pages while keeping it off of custom post types.

    Thanks again!

    » Reply

  9. Wow! This blog looks just like my old one! It’s on a entirely different subject but it has pretty much the same page layout and design. Great choice of colors!

    » Reply

Add a comment

Your email address will not be published.

Required