WordPress.org

Ready to get started?Download WordPress

Forums

Share Buttons by AddThis
[Plugin: AddThis] Support for Custom Post Types (8 posts)

  1. ajuliano
    Member
    Posted 2 years ago #

    I'm using this plugin on a website with three different custom post types, but I only wanted the AddThis-buttons to be displayed on Posts.

    Unfortunately this plugin doesn't have support for hiding the buttons on Custom Post Types. I added two lines of code to hide it on my Custom Post Types, but i think it would be better to have an option on the settings-screen.

    I added this on line 1183 in the file addthis_social_widget.php:

    elseif ( 'my_custom_post_type' == get_post_type() )
        	$display = false;

    http://wordpress.org/extend/plugins/addthis/

  2. Aaron Jorbin
    Member
    Posted 2 years ago #

    Hi Ajuliano,

    The best way to remove it from custom post types would be to use the addthis_post_exclude filter. You could do something along the lines of:

    add_filter('addthis_post_exclude', 'my_addthis_post_exclude_filter');
    function my_addthis_post_exclude_filter($display)
    {
    if ( 'my_custom_post_type' == get_post_type() )
        $display = false;
    
    return $display;
    }
  3. madhavaji
    Member
    Posted 2 years ago #

    Hey Aaron,

    Great fix my man.. works like a charm :)

    Michael.

  4. stevemagruder
    Member
    Posted 2 years ago #

    This worked for me too, thanks!

    I'd note that in my case, the post type I had to use in this scenario was blank (''), as it wasn't reported by the plugin that created the post type. I say this in case anyone runs into something like this.

  5. ajuliano
    Member
    Posted 2 years ago #

    Thank you Aaron!

    Worked great for me as well.

    Although I use switch, because I've got multiple post-types to hide it from.

    add_filter('addthis_post_exclude', 'my_addthis_post_exclude_filter');
    function my_addthis_post_exclude_filter( $display ) {
    	switch ( get_post_type() ) {
    		case 'my_post_type_1':
    			$display = false;
    			break;
    		case 'my_post_type_2':
    			$display = false;
    			break;
    		case 'my_post_type_3':
    			$display = false;
    			break;
    		case 'my_post_type_4':
    			$display = false;
    			break;
    	}
    
    	return $display;
    }

    Do you think there's a better way of doing it?

  6. stevemagruder
    Member
    Posted 2 years ago #

    ajuliano, here's a much simpler way:

    add_filter('addthis_post_exclude', 'my_addthis_post_exclude_filter');
    function my_addthis_post_exclude_filter($display)
    {
    if ( in_array(get_post_type(), array('my_post_type_1', 'my_post_type_2','my_post_type_3','my_post_type_4')) )
        $display = false;
    
    return $display;
    }
  7. majakovskij
    Member
    Posted 2 years ago #

    Thank you all for the tip!!

  8. Agnes
    Member
    Posted 2 years ago #

    I found a way to insert a custom style in my template, according to this page:
    http://www.addthis.com/blog/2011/03/03/addthis-for-wordpress-plugin-version-2-0-2/#.T6Op0Os5Ld4

    I added my style as an array in the plugin file (addthis_social_widget.php)

    $addthis_new_styles = array(
    
        'my_style' => array( 'src' =>  '<div class="addthis_toolbox addthis_default_style addthis_" %s ><a class="addthis_button_facebook"></a><a class="addthis_button_twitter"></a><a class="addthis_button_google_plusone_share"></a><a href="http://www.addthis.com/bookmark.php?v=250&pubid=ra-4fa382503d81907c" class="addthis_button_compact">
    <a class="addthis_button_email"></a><a class="addthis_button_print"></a><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a></div>', 'img' => 'toolbox-small.png', 'name' => 'My Style', 'above' => 'hidden ', 'below' => ''
        ), // My Style

    And then added the code manually in the template with my style

    <?php do_action('addthis_widget',get_permalink($post->ID), get_the_title($post->ID), 'my_style'); ?>

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags