WordPress Permalink URL for Add This Sharing

AddThis is the leading developer tool for sharing your blog posts, pages, and pics. Just embed the simple code into your website, and visitors will be able to share your content with all of the leading social media networks with just a click. It’s an essential tool.

Today I will be showing you how to embed this into your WordPress site. By placing this directly into the WordPress Loop, ADDthis will now be displayed for every post that is called.

You need to do this for at least 2 pages. The index.php file and the single.php file. It is also a good idea to place it within your archive.php file as well.

Here’s how :

1. Find the WordPress loop

Open any of the following files (index.php, single.php, archive.php) and find your WordPress loop. The coding looks like this :

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

That tells WordPress to call to any post and display whatever follows until the loop is over.

2. Grab the AddThis code for your site

What you need to do is place the code AddThis provides into wherever you see fit into the post. Let’s hop over to AddThis and get the code.

Follow that URL and hit ‘Get AddThis.’ Copy the code it provides for whatever look you select.

3. Place the code within the Loop

Place that code within your Loop now wherever you wish. You will probably need to style it somehow once all is said and done, but it should look something like this :

<div class="addthis_toolbox addthis_default_style ">
	<a class="addthis_button_preferred_1"></a>
	<a class="addthis_button_preferred_2"></a>
	<a class="addthis_button_preferred_3"></a>
	<a class="addthis_button_preferred_4"></a>
	<a class="addthis_button_compact"></a>
	<a class="addthis_counter addthis_bubble_style"></a>
</div>
<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4e113d4c14185562"></script>

What this is saying is basically : While you have a WordPress Loop, display the title, and then below it, display the AddThis tool.

Now this works good and well except for one thing. Your AddThis tool will grab the URL from the current page and attempt to share it.

What if you have a index.php page that displays multiple posts on one page? How will a visitor share just one post on that page? WE NEED TO FIX THAT!!

4. Add a Permalink URL to the AddThis script

There is a simple line that you need to add to make the AddThis tool fully functional within the WordPress Loop. Find the very first line :

<div class="addthis_toolbox addthis_default_style ">

and add this :

 addthis:url="<?php the_permalink() ?>"

so it appears as :

<div class="addthis_toolbox addthis_default_style " addthis:url="<?php the_permalink() ?>">

That’s it! Now, whenever AddThis is used, it calls to the Permalink of each individual post and that URL as opposed to the full page.

Get to sharing!

5 Comments

  • Love this post!!

  • There’s gotta be an easier way to do this!

  • Very informative post! I was trying to find a way to embed this on every index.php file I had in my entire library portfolio!

    Can you tell me how to display this in archive.php in more detail? I can’t figure out what line I should be putting this on.

    Otherwise, great post!

  • where should I put this in my header.php file?

  • very cool post. I’ve been looking for this for a while.

Leave A Comment

Your email address will not be published. Required fields are marked *