How to create a Pinterest “pin it” button for your WordPress blog

November 19, 2012 at 5:19 pm

As a blogger or website owner, your goal is probably to attract traffic to your website. While facebook and twitter are definitely the two bigger social networking sites, Pinterest is also bringing lots of traffic to blogs. So what about adding a pinterest “Pin It” button to your blog? Let’s do it.

The first thing to do is to paste the following snippet where you’d like the “Pin It” button to be displayed. Note that this code must be inserted within the loop.

<a href="http://pinterest.com/pin/create/button/?url=<?php the_permalink(); ?>&media=<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail' ); echo $thumb['0']; ?>&description=<?php the_title(); ?>" class="pin-it-button" count-layout="horizontal">Pin It</a>

Once done, open your footer.php file and add the pinterest JavaScript code:

<script type="text/javascript" src="http://assets.pinterest.com/js/pinit.js"></script>

Thanks to Douglas Karr for the cool code!

Tags: