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!
6 Responses
Thanks but If I were you I’d use the_title_attribute() to avoid bad surprise with fancy title
Thnaks but you should use the_title_attribute() instead of the_title() to avoid bad surprise if title contains “..”
Thanks for sharing. I was looking for a pinterest button code.
Thanks for the quick tip! I normally use an entire social bar like AddThis, but I’ve been thinking of using a lone Pinterest button on certain sites.
Impressive snippet, love it .
Easy to use and hassle free.
Will it also add a counter with pinterest icon? I want to add a counter but my client requires to start this counter from 100.. Is it also possible?
Trackbacks: