Automatically Placing AddThis in Every WordPress Post

Posted by Alex | Other | Friday 16 October 2009 12:40 am

Bookmark and Share

If you’re like me and are not satisfied with the default position of the AddThis button with the plugin, which is at the bottom of each post, but don’t want to add code manually to each post, don’t get discouraged.

Go to your theme editor and open up single.php (Single Post)

Make sure you have the default AddThis code copied to your clipboard. The code is as follows:

<!– AddThis Button BEGIN –>
<a href=”http://www.addthis.com/bookmark.php?v=250&amp;pub=xa-4ad7e7a319fc026d”><img src=”http://s7.addthis.com/static/btn/v2/lg-bookmark-en.gif” width=”125″ height=”16″ alt=”Bookmark and Share” style=”border:0″/></a><script type=”text/javascript” src=”http://s7.addthis.com/js/250/addthis_widget.js#pub=xa-4ad7e7a319fc026d”></script>
<!– AddThis Button END –>

Your current single.php should look something like this:

<?php
get_header();
?>

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<div>
<h2 id=”post-<?php the_ID(); ?>”><a href=”<?php the_permalink() ?>” rel=”bookmark”><?php the_title(); ?></a></h2>

<div><?php _e(“Posted by”); ?> <?php the_author() ?> | <?php the_category(‘,’) ?> | <?php the_time(‘l j F Y’); ?> <?php the_time() ?> </div>
<br />

<div>

<?php the_content(__(‘(more…)’)); ?>
</div>

<div>
<?php wp_link_pages(); ?>
<?php comments_popup_link(__(‘Comments (0)’), __(‘Comments (1)’), __(‘Comments (%)’)); ?>
</div>

<?php comments_template(); // Get wp-comments.php template ?>

<?php endwhile; else: ?>
<p><?php _e(‘Sorry, no posts matched your criteria.’); ?></p>
<?php endif; ?>

<?php posts_nav_link(‘ &#8212; ‘, __(‘&laquo; Previous Page’), __(‘Next Page &raquo;’)); ?>
</div>

<?php get_footer(); ?>

Place the AddThis code wherever you want –putting it inside the <h2> tag places it in the header of the post, putting it after the </h2> tag will make it appear after the header obviously.

Remember, these are just examples of what your single.php could look like. Different themes have different codes so adjust accordingly and good luck!

Did this work for you or are you still having problems? Leave us a comment below

  • http://www.walkingtaco.com/ Simon

    Wow man, this post was just what I needed. Not even kidding. I've been trying to figure this out for a long time, and the AddThis support hasn't been very helpful. Thanks a lot!