Recently while monitoring our blog stats, a new traffic source was popping up enough for us to notice. This traffic source was Pinterest. We started using the platform and saw great potential in it. In this article, we will show you how to add the Pinterest “Pin It” button to your WordPress blog.

Pinterest “Pin It” Button

First thing you need to do is paste the following script in your footer.php file right before the body close tag.

<script type="text/javascript">
(function() {
    window.PinIt = window.PinIt || { loaded:false };
    if (window.PinIt.loaded) return;
    window.PinIt.loaded = true;
    function async_load(){
        var s = document.createElement("script");
        s.type = "text/javascript";
        s.async = true;
        s.src = "http://assets.pinterest.com/js/pinit.js";
        var x = document.getElementsByTagName("script")[0];
        x.parentNode.insertBefore(s, x);
    }
    if (window.attachEvent)
        window.attachEvent("onload", async_load);
    else
        window.addEventListener("load", async_load, false);
})();
</script>

Once you have done that, you can add the following code in your single.php file at a location of your choice:

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

The code above is basically pulling your Featured Image, the title of your post as description, and the URL of the post. It is designed for the vertical share button. If you want to put the horizontal share button, simply change count-layout parameter to horizontal.

Pinterest Shortcode

One of our user wanted to create a shortcode for the Pinterest “Pin It” button. You can easily do so by pasting the following code either in your theme’s functions.php file or your site plugin’s file:

<?php
function get_pin($atts) {
$pinterestimage = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
return '<a href="http://pinterest.com/pin/create/button/?url' . urlencode(get_permalink($post->ID)) . '&media=' . $pinterestimage[0] . '&description=' . get_the_title() .'" class="pin-it-button" count-layout="vertical">Pin It</a>'; }
add_shortcode('pin', 'get_pin');
?>




pin it button, add pinterest button to wordpress, how to add pinterest button to wordpress blog, pin it button on wordpress, how to add a pinterest button to wordpress, pinterest share button, pinterest button wordpress, pinterest vertical button with count, how to get the pin it button, how do i add a pinterest button to my wordpress blog

Related articles:

  1. How to Add the Google +1 Button to your WordPress
  2. 5 Free Pinterest WordPress Plugins
  3. 8 Free Google+ Button & Google Plus Profile WordPress Plugins
  4. How to Add a Tweet Button Anywhere
  5. Scheduling Blog Posts and Automating Everything Else