Self-confessed Starbucks addict from the suburbs of Chicago.

How to Add a Pinterest “Pin It” Button to Your Site

Add a Pinterest

For those of you who live under a rock, there’s a new rage on the internet and it’s called Pinterest. Here’s what it is:

Pinterest lets you organize and share all the beautiful things you find on the web. People use pinboards to plan their weddings, decorate their homes, and organize their favorite recipes.

If you’re like most of us, you know exactly what Pinterest is, and you’ve probably heard a number of people talking about it. Some people think that Pinterest is a “timesuck” or “online bulletin board”, but to others it’s a huge source of traffic.

Don’t Believe Me?

ProBlogger founder Darren Rowse wrote a really good blog post recently about how he overlooked a 1000 visitor a day source of traffic.

Or you can see what Nester thinks about Pinterest and blogging. She’s a home decor blogger, and knows a thing or two about that niche.

Many folks are pigeonholing Pinterest as a website for women – but I’m seeing more and more people (as in guy friends of mine) sign up and using it as well.

Adding the “Pin It” Button

I won’t tortue you any more, so here’s how you add a Pinterest “Pin It” button to your site. As with all tutorials, this assumes you’re using the Genesis Framework.

The first step is to create a file named single.php and place the code you see below. Save the file and upload it to your child theme’s directory on your server.

With Pinterest, you have three options for the “Pin It” button display – horizontal, vertical and no count. Choose one of the three options – not all of them.

Horizontal button display:

<?php
add_action( 'genesis_post_content', 'pinterest_share_button', 5 );
function pinterest_share_button() {
	
    /** Horizontal */
    printf( '<div class="pinterest-button"><a href="http://pinterest.com/pin/create/button/?url=%s&media=%s" class="pin-it-button" count-layout="horizontal">Pin It</a><script type="text/javascript" src="http://assets.pinterest.com/js/pinit.js"></script></div>', urlencode( get_permalink() ), urlencode( genesis_get_image( array( 'format' => 'url' ) ) ) );

}

genesis();

Vertical button display:

<?php
add_action( 'genesis_post_content', 'pinterest_share_button', 5 );
function pinterest_share_button() {
	
    /** Vertical */
    printf( '<div class="pinterest-button"><a href="http://pinterest.com/pin/create/button/?url=%s&media=%s" class="pin-it-button" count-layout="vertical">Pin It</a><script type="text/javascript" src="http://assets.pinterest.com/js/pinit.js"></script></div>', urlencode( get_permalink() ), urlencode( genesis_get_image( array( 'format' => 'url' ) ) ) );

}

genesis();

No-count button display:

<?php
add_action( 'genesis_post_content', 'pinterest_share_button', 5 );
function pinterest_share_button() {
	
    /** No-count */
    printf( '<div class="pinterest-button"><a href="http://pinterest.com/pin/create/button/?url=%s&media=%s" class="pin-it-button" count-layout="none">Pin It</a><script type="text/javascript" src="http://assets.pinterest.com/js/pinit.js"></script></div>', urlencode( get_permalink() ), urlencode( genesis_get_image( array( 'format' => 'url' ) ) ) );

}

genesis();

Which Image Will Show?

The pinterest_share_button function will pull in the genesis_get_image function, which first searches your post to see if you have set a Featured Image.

If you haven’t set a Featured Image, the fallback will be the first image found in the gallery for that particular post.

Placing the Pinterest “Pin It” Button

The sample code given above will place the Pin It button directly above your post content. If you’d like to display it after the post content, replace this code:

add_action( 'genesis_post_content', 'pinterest_share_button', 5 );

With this code:

add_action( 'genesis_post_content', 'pinterest_share_button' );

If you would like to place the Pin It button before and after the post content, your entire single.php file would look like this:

<?php
add_action( 'genesis_post_content', 'pinterest_share_button', 5 );
function pinterest_share_button() {
	
    /** Horizontal */
    printf( '<div class="pinterest-button"><a href="http://pinterest.com/pin/create/button/?url=%s&media=%s" class="pin-it-button" count-layout="horizontal">Pin It</a><script type="text/javascript" src="http://assets.pinterest.com/js/pinit.js"></script></div>', urlencode( get_permalink() ), urlencode( genesis_get_image( array( 'format' => 'url' ) ) ) );

}

add_action( 'genesis_post_content', 'pinterest_share_button_after' );
function pinterest_share_button_after() {
	
    /** Horizontal */
    printf( '<div class="pinterest-button"><a href="http://pinterest.com/pin/create/button/?url=%s&media=%s" class="pin-it-button" count-layout="horizontal">Pin It</a><script type="text/javascript" src="http://assets.pinterest.com/js/pinit.js"></script></div>', urlencode( get_permalink() ), urlencode( genesis_get_image( array( 'format' => 'url' ) ) ) );

}

genesis();

Styling the Pinterest “Pin It” Button

There probably isn’t much that you’ll want to style with the “Pin It” button. Depending on where you place it you might want to adjust margin or padding.

Here’s how you can target the Pinterest “Pin It” button through CSS:

.pinterest-button iframe {
    margin: 10px 0;
}

Oh – by the way – if you’re a business or consumer and want to connect with others on Pinterest, check out Pin Savvy Social.

Special Thanks
Thanks to Nathan Rice for writing the Pinterest “Pin It” function used in this tutorial.

Comments

  1. Norcross says:

    I am personally waiting for them to open their API so I can do some more things with it, i.e pull in photos, etc. Sucks that I can’t.

  2. Tris Hussey says:

    Sweet! Less than a minute and done! Works great Brian!

  3. Phil Derksen says:

    I recently started work on a simple Pinterest Pin It button plugin after I ran into issues adding it to my WP sites. Features are minimal at the moment but it gets the job done and I’m working on requests from folks such as placement an display options.

    http://wordpress.org/extend/plugins/pinterest-pin-it-button/

    It mimics the JavaScript behavior of their bookmarklet rather than their “add to your website” code that you used.

    Other than that, I got a hold of a developer at Pinterest and they say they’re working on an API currently. But no timeline as to when it will be released to the public.

    • Phil – thanks for dropping by and linking to your plugin. I actually considered writing this tutorial with your plugin in mind, but I’m trying my best to teach people how to do things with Genesis here on the site. Either way works the same probably. :-)

      • Jon Brown says:

        I like Phil’s plugin, which is getting better by the day… but I also like doing things like this without plugins a lot of the time. So kudos to you both.

  4. love this & will be adding it to my site: FancyLittleThings.com as soon as we move over to Genesis {when my design schedule allows!!} – we currently use this plugin: http://flauntyoursite.com/pin-it-on-pinterest/ but look forward to leaving it in the dust!! thanks for another great post.

  5. Kelly Exeter says:

    Thanks so much for this Brian! I was using the Pinterest “Pin It” plugin on my website but it was putting the “Pin It” button underneath my related post stuff where no one can see it – and it was doing my head in!

  6. Matt says:

    Is there anyway to add it to the Jetpack sharing tool?

    • I doubt it – that’s something that TPTB over at Automattic would have to decide.

    • I just tried adding it in as ‘another service’ and it’s possible to add it in but you can only do it for one url and have to predefine the image and everything.

      Brian’s way of doing it here is definitely the best way to go about adding it to your site.

      However, it would be nice to see a mini tutorial on adding a similar set of social sharing buttons to posts like the ones in Jetpack. Brian? :)

      • I hear ya Paul – I tried the “simple” code given by Pinterest and yes, it required a manual setting of URL and image for each one. That’s why I insisted that Nathan write up something with the “all inclusive” style for pinning posts.

  7. The Frosty says:

    Just wrote a post last night about adding the Pinterest button to your blog… My post shows how to append it to Jetpack’s Sharedaddy share bar with jQuery.

  8. Can I just check – by adding this material to child theme it will not get overwritten by genesis framework update?
    What if child theme gets updated by studiopress – will there be a a way to save anyof these child theme mods?

    • Mike, child themes are never affected (files getting overwritten, etc) when Genesis is updated. Child themes themselves are seldom updated, and even when they are it’s usually minor stuff.

  9. David Decker says:

    Thanx Brian for the tip :) — I place the hook/function code in my functions.php or via Simple Hooks plugin, so no new template file (single.php) is necessary at all ;-)

  10. Jessica says:

    Thanks so much for the link Brian, such a great tutorial, linked to you in our sidebar as a resource.

  11. I’ve been trying to built the button in for a few weeks now but was having problems getting the thumbnail to work. Thanks for sharing this Brian!

  12. Jay Thompson says:

    Of note. I had an existing single.php file so I just added the code above to that file (above the closing “genesis( );” line). It error’ed out unless I *removed* the “<?php" from the copied code. I'm sure a real coder would find that obvious, but I'm a hack…

    • Yea, the tutorial assumes it’s a fresh file, which is why the opening php line is there. Obviously you figured out the hard way Jay, but like you said – you’re a hack. Like me, you seem to learn by trial and error, also known as being street smart. (sometimes I think that’s a better trait than being book smart!) :-)

  13. Thank you Brian for the tutorial and Nathan for the code, I added it to my main sites. I’m loving Pinterest! – Eleanor

  14. Works awesome like was mentioned above!
    Any chance there’s a way to add this button along side the tweet button in the post info area?

  15. Thank you Brian! I hated having a plugin installed just for that. Makes it much easier. Hate where it puts it when setting it for the bottom of the post, but I don’t mind keeping it at the top.

  16. Stewart Cook says:

    Thanks Brian for the tutorial. No doubt Pinterest is on the rise and designers/developers and DIYers alike should be aware of how to integrate this on their sites.

  17. Thank you so much, Brian! This worked great and was very easy to set up.

    I’d love to be able to add a Tweet button alongside, too.

  18. Mike says:

    Perfect timing. I just had a client request this feature for her catering and recipe website.

    Love Studiopress and Genesis. So much bang for the buck.

  19. David says:

    Any idea on how to get the Pinterest and Facebook buttons side-by-side? My code is working but they are stacked.

    Here it is:

    ID ), ‘full’ ); ?>
    <a href="http://pinterest.com/pin/create/button/?url=ID)); ?>&media=&description=” class=”pin-it-button” count-layout=”horizontal”>Pin It

    Thanks for any help,

    David

  20. Ethan says:

    Hi Brian,
    Thanks for this. I tried this method and got this error on each blog post.
    “Parse error: syntax error, unexpected T_STRING in …[edited]… themes/eleven40/single.php on line 9″

    Any ideas about line 9? I was using the 1st code listed for the horizontal display button.

    Thanks

    • I’m guessing you missed something in the copy and paste. Have you been able to get it to work?

      • Ethan says:

        Not yet. I did double check my copy/paste. But just because, yes, I’m a hack…
        The file does go in the Child Theme’s main directory, correct? Not Some other directory?
        Thanks

      • Ethan says:

        No. sad face…I’m using a plugin.

        I’ll try again, but each time I copy re-paste, the blog posts get shut down with that error message.

        Feeling pretty incompetent right now. Outside of me actually learning to code, yes, you’ll be enabling me, any consoling professional advice on why adding that code gives that error?

        Thanks again

  21. Bill Gassett says:

    No doubt the latest and greatest social media tool. Everywhere I go I am seeing this new social tool. Thanks for the tutorial as I am a Genesis member:)

  22. Wendy says:

    I am wondering what would be the best way to include the Pinterest button along with Facebook, Twitter, etc. in Genesis. I have some experience with Thesis custom functions. Genesis seems somewhat similar with regard to hooks but I am a newbie and have not gotten the hang of Genesis yet. Thanks in advance for your help.

  23. Rachael says:

    Brian, Thanks so much for the awesome tutorial. I was struggling getting the images to show up with another plugin. I remembered you had tutorials on your site and sure enough you had one for Pinterest. I uploaded the single.php and it worked perfectly right away! Thanks again!

Speak Your Mind

*