Exclude Digg Digg from Custom Post Types

If you’ve used the Digg Digg plugin before to entice social sharing and increase social signals, you may have noticed the lack of the ability to specify exclusion from certain custom post types for the normal and the floating display. It’s either all posts or none.

However, if you’re comfortable with editing and pasting in code into your themes functions.php file, then here is a possible solution for you:

function exclude_diggdigg() {
    if (get_post_type() == 'event') {
        remove_filter('the_excerpt', 'dd_hook_wp_content');
        remove_filter('the_content', 'dd_hook_wp_content');
    }
}
add_action('template_redirect', 'exclude_diggdigg');

The function above checks to see if the current page has a post type of “event”, but you can modify that to check for your own custom post type.

Exclude Multiple Custom Post Types:

If you need to disable the Digg Digg plugin from displaying for multiple custom post types but not all, then you could use the following code:

function exclude_diggdigg() {
    if (in_array(get_post_type(),array('event','location','staff'))) {
        remove_filter('the_excerpt', 'dd_hook_wp_content');
        remove_filter('the_content', 'dd_hook_wp_content');
    }
}
add_action('template_redirect', 'exclude_diggdigg');

Naturally, you’ll need to edit the custom post type names specified in the array.

Exclude All Custom Post Types:

We can go a step further, and just disable Digg Digg for all custom post types with the following:

function exclude_diggdigg() {
    if (get_post_type() !== 'post') {
        remove_filter('the_excerpt', 'dd_hook_wp_content');
        remove_filter('the_content', 'dd_hook_wp_content');
    }
}
add_action('template_redirect', 'exclude_diggdigg');