Self-confessed Starbucks addict from the suburbs of Chicago.

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

Posted on January 24, 2012 · 46 Comments · Tweet

spacer

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( '<a class="pinterest.com/pin/create/button/?url=%s&media=%s" count-layout="horizontal">Pin It</a><script type="text/javascript" src="/img/spacer.gif"> 

Vertical button display:

<?php
add_action( 'genesis_post_content', 'pinterest_share_button', 5 );
function pinterest_share_button() {
	
    /** Vertical */
    printf( '<a class="pinterest.com/pin/create/button/?url=%s&media=%s" count-layout="vertical">Pin It</a><script type="text/javascript" src="/img/spacer.gif"> 

No-count button display:

<?php
add_action( 'genesis_post_content', 'pinterest_share_button', 5 );
function pinterest_share_button() {
	
    /** No-count */
    printf( '<a class="pinterest.com/pin/create/button/?url=%s&media=%s" count-layout="none">Pin It</a><script type="text/javascript" src="/img/spacer.gif"> 

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( '<a class="pinterest.com/pin/create/button/?url=%s&media=%s" count-layout="horizontal">Pin It</a><script type="text/javascript" src="/img/spacer.gif"> 

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:

.entry-content br {
    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.

Sign up for my Newsletter:

  • General WordPress Tips and How-To's
  • Code Snippets for the Genesis Framework
  • Detailed Tutorials on Building a Custom Genesis Site
  • Internet Tricks of the Trade - Design, Social Media and More

Whatcha waiting for?

Comments

  1. spacer Norcross says:
    January 24, 2012 at 2:39 pm

    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.

    Reply
    • spacer Brian Gardner says:
      January 24, 2012 at 2:42 pm

      Yeah – I’m sure it’s only a matter of time before they figure out that an open API would be a good thing for developers.

      Reply
  2. spacer Tris Hussey says:
    January 24, 2012 at 2:46 pm

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

    Reply
    • spacer Brian Gardner says:
      January 24, 2012 at 6:54 pm

      Awesome Tris – glad to hear it!

      Reply
  3. spacer Phil Derksen says:
    January 24, 2012 at 5:23 pm

    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.

    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.

    Reply
    • spacer Brian Gardner says:
      January 24, 2012 at 5:41 pm

      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. spacer

      Reply
      • spacer Jon Brown says:
        January 31, 2012 at 3:39 pm

        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.

        Reply
  4. spacer Aimee Steckowski says:
    January 24, 2012 at 5:26 pm

    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: flauntyoursite.com/pin-it-on-pinterest/ but look forward to leaving it in the dust!! thanks for another great post.

    Reply
    • spacer Brian Gardner says:
      January 24, 2012 at 5:40 pm

      Thanks Aimee, as I had answered someone over on my Google+ thread, I prefer to use simple native code for functionalities like this so that I don’t have to rely on 3rd party plugins and experience possible compatibility issues down the road.

      Reply
      • spacer Aimee Steckowski says:
        January 24, 2012 at 5:54 pm

        love that we have the option on Genesis. good stuff Brian!!

        Reply
  5. spacer Kelly Exeter says:
    January 24, 2012 at 6:52 pm

    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!

    Reply
    • spacer Brian Gardner says:
      January 24, 2012 at 6:53 pm

      You betcha – have you had a chance to use this code instead and is it placing the Pin It button in the proper spot?

      Reply
  6. spacer Matt says:
    January 24, 2012 at 8:57 pm

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

    Reply
    • spacer Brian Gardner says:
      January 24, 2012 at 10:59 pm

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

      Reply
    • spacer Paul Letourneau says:
      January 25, 2012 at 3:03 pm

      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? spacer

      Reply
      • spacer Brian Gardner says:
        January 26, 2012 at 9:25 pm

        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.

        Reply
  7. spacer The Frosty says:
    January 24, 2012 at 11:32 pm

    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.

    Reply
    • spacer Brian Gardner says:
      January 24, 2012 at 11:34 pm

      Good stuff Austin – and thanks for sharing. Sounds like this is a universal way of adding it to any theme – right?

      Reply
  8. spacer mike mcsharry says:
    January 25, 2012 at 6:51 am

    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?

    Reply
    • spacer Brian Gardner says:
      January 25, 2012 at 8:40 am

      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.

      Reply
  9. spacer David Decker says:
    January 25, 2012 at 7:24 am

    Thanx Brian for the tip spacer — 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 spacer

    Reply
  10. spacer Jessica says:
    January 25, 2012 at 8:29 am

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

    Reply
    • spacer Brian Gardner says:
      January 25, 2012 at 8:40 am

      Thank YOU Jessica as well – hopefully you got some traffic last night as I also tweeted about your services!

      Reply
  11. spacer Scott Wyden Kivowitz says:
    January 25, 2012 at 9:28 am

    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!

    Reply
  12. spacer Jay Thompson says:
    January 26, 2012 at 9:20 pm

    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…

    Reply
    • spacer Brian Gardner says:
      January 26, 2012 at 9:24 pm

      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!) spacer

      Reply
      • spacer Jay Thompson says:
        January 26, 2012 at 9:37 pm

        spacer I’ve been working on both my kids for 18-something years to be street smart…

        Reply
  13. spacer Eleanor Prior says:
    January 28, 2012 at 2:15 pm

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

    Reply
  14. spacer Paul Letourneau says:
    January 29, 2012 at 6:03 pm

    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?

    Reply
  15. spacer Shawn Ann @ Shawn Ann's World says:
    January 30, 2012 at 9:28 am

    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.

    Reply
    • spacer Brian Gardner says:
      January 30, 2012 at 10:06 am

      Good to hear – always happy to know that I’ve solved a problem for folks and also that it requires one less plugin. spacer

      Reply
  16. spacer Stewart Cook says:
    January 30, 2012 at 1:16 pm

    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.

    Reply
  17. spacer Cindy @ Scrapbook Dimensions says:
    January 30, 2012 at 5:56 pm

    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.

    Reply
    • spacer Brian Gardner says:
      January 30, 2012 at 8:13 pm

      Great to hear it Cindy! I’ll see if I can manage a Twitter tutorial soon.

      Reply
  18. spacer Mike says:
    February 1, 2012 at 9:58 am

    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.

    Reply
    • spacer Brian Gardner says:
      February 1, 2012 at 11:28 am