WordPress.org

Ready to get started?Download WordPress

Forums

Share Buttons by AddThis
Limit AddThis to just main loop, not custom WP_Query in footer (6 posts)

  1. tzeldin88
    Member
    Posted 6 months ago #

    The AddThis plugin correctly adds the Share-Buttons to the end of my posts, as expected. But they ALSO display in my site footer, which is populated by a custom WP_Query call in my footer.php template file.

    I tried using a hook to disable display of the Share buttons for any post-type other than 'post', using this -

    add_filter('addthis_post_exclude', 'addthis_post_exclude');
    function addthis_post_exclude($display) {
    	global $post;
    	if( get_post_type($post->ID) != 'post' ){
    		$display = false;
    	}
    	return $display;
    }

    but it didn't solve the problem -- the Share-Buttons still display incorrectly in the footer on a post page.

    So it seems the AddThis plugin does not actually limit itself to the loop -- it also goes into any custom WP_Query on the page.

    Seems like a bug. Any solution?

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

  2. srijith.v
    AddThis Samurai
    Plugin Author

    Posted 6 months ago #

    @tzeldin88: Plugin will listen to the_content and the_excerpt hooks and will print according to the configuration. If you are using a custom WP_Query, this shouldn't happen. I would like to have a look at your theme file where the query is being made to see what's going wrong. If possible, can you add srijith[AT]addthis.com to your users and grant access to the dashboard? If not, send the theme code snippet with the query and your configuration screenshot for AddThis Share plugin to the same email.

  3. tzeldin88
    Member
    Posted 4 months ago #

    I am using the_content() in my custom WP_Query, outside the main loop for the page, to display something in the sidebar and footer. So if the AddThis plugin just listens for "the_content()" then it seems like that's a problem with the plugin -- since the_content() can be called multiple times on a page. I have seen this problem on multiple sites now.

    I can't give direct access to my wp site. My code is a just a basic use of WP_Query outside the loop.

    $args = array(
    	'post_type' => 'page',
    	'post__in'  => array($page_id)
    );
    $the_query = new WP_Query( $args );
    while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    		<?php the_content();?>
    <?php
    	endwhile;
    	wp_reset_postdata(); //reset query

    My code works fine -- except that the AddThis buttons insert themselves at the end of the displayed content.

    My AddThis settings are-
    on the Basic tab:
    - Bottom Sharing Tool enabled
    - custom button (but the problem persists with other options)
    on the Advanced tab:
    - show on Homepage, Pages,
    - Show analytics in admin dashboard: yes
    - nothing else set.

    I also posted about this on the AddThis support site, and got no help there.
    http://support.addthis.com/customer/portal/questions/3359303-wp-addthis-plugin-inserts-share-buttons-in-wp-query-calls-outside-the-loop

  4. tzeldin88
    Member
    Posted 4 months ago #

    By the way, I know i can just hide the errant AddThis display, by using CSS display:none, but that's not ideal.

  5. srijith.v
    AddThis Samurai
    Plugin Author

    Posted 4 months ago #

    @tzeldin88: Yes, the plugin will render buttons when the_content() is being called. For custom placement, you may try the template tag option. First you have to set 'Do not Show' to display options in the plugin configuration for both 'above' and 'below'. Then, in your theme file, use a template tag like:

    <?php do_action( 'addthis_widget', get_permalink(), get_the_title(), array(
    		'size' => '16',
    		'services' => 'twitter',
    		'preferred' => '3',
    		'more' => true,
                    'type' => 'custom',
    		));
    	?>
  6. tzeldin88
    Member
    Posted 4 months ago #

    Ahhhh, thank you for confirming that the AddThis plugin does indeed insert itself into any call of the_content(), even those outside the loop. This seems like a problem with the plugin -- I would think it should just have a config option like "__ constrain to main-loop only", to prevent this.

    Also, thanks for the template-tag code. That can help me in some situations/sites, but unfortunately not the one i'm currently doing. And surely many users of this plugin won't understand this kind of solution. I'm really surprised I couldn't find more bug/support requests about it.

    But again, thank you for your response, honesty, and assistance.

Reply

You must log in to post.

About this Plugin

About this Topic