WordPress Permalink URL for Add This Sharing

July 4, 2011

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 :

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 :

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 :

and add this :

so it appears as :

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

  • Jessica

    Love this post!!

  • Chris

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

  • Jonathan Huxtable

    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!

  • mohat

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

  • John

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

Leave a Reply

Your email address will not be published.