In case you haven’t heard, there’s a new rage in social media and it’s called Pinterest. Pinterest lets you organize and share all the beautiful things you find on the web. People use pinboards to plan weddings, decorate their homes, and organize their 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;
}
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.
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.
Sweet! Less than a minute and done! Works great Brian!
Awesome Tris – glad to hear it!
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.
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.
Brian and Phil,
Great post! And thanks for both the code and the plugin. I prefer to use plugins most of the time, but nice to have the code as reference!
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.
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.
love that we have the option on Genesis. good stuff Brian!!
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!
You betcha – have you had a chance to use this code instead and is it placing the Pin It button in the proper spot?
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.
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.
Good stuff Austin – and thanks for sharing. Sounds like this is a universal way of adding it to any theme – right?
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.
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
Thanks so much for the link Brian, such a great tutorial, linked to you in our sidebar as a resource.
Thank YOU Jessica as well – hopefully you got some traffic last night as I also tweeted about your services!
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!
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!)
Thank you Brian for the tutorial and Nathan for the code, I added it to my main sites. I’m loving Pinterest! – Eleanor
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?
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.
Good to hear – always happy to know that I’ve solved a problem for folks and also that it requires one less plugin.
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.
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.
Great to hear it Cindy! I’ll see if I can manage a Twitter tutorial soon.
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.
See this comment.
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
Hard to say without seeing a sample blog post. Can you link to one/
Yes sure. It doesn’t seem like the code was visible either. Here it is again:
//ID ), ‘full’ ); ?>
<a href="http://pinterest.com/pin/create/button/?url=ID)); ?>&media=&description=” class=”pin-it-button” count-layout=”horizontal”>Pin It//
And here’s a link:
http://www.damyhealth.com/2012/02/cookie-dough-hummus-5-minute-recipe/
Thanks so much for your help.
David
Looks like you got this to work?
Yes, I got it figured out. Thanks again for your help. I appreciate it.
David
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?
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
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
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:)
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.
That’s something that should probably come by way of a social share plugin, or at the very least use our Genesis Simple Hooks plugin to add the necessary code.
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!
Hey Rachel – awesome, so glad to hear this worked for you!
This is great.
Only thing I will add is that if you are planning on using this with multiple instances on a page (say your archive pages) you can add this to you Genesis Settings > Header Scripts:
… and then leave out the inline javascript call.
I used Phil’s Pinterest “Pin It” Button plugin. I was able to align the button with my Facebook “Like” button very easily. Thank You ;p
I’ve had a headache for days trying to figure out how to add a pin it button to my post. You have no idea how much I appreciate this post. I now have a pin it button. Thank you so much.
Is there an easy way to add a feature image? My images aren’t showing whey I try to pin from my posts. I’m new to Genesis Framework and I’m a dork on top of that so I’m pretty sure I don’t know what I’m doing 99% of the time
.
Do you have any images in the post itself?
Hi! thank you a lot for this tutorial
I’ll try to add Pin It button on my blog.
I’m having a pinterest problem that I can’t figure out even after 3 hours of googling the issue. When someone goes to my site and wants to pin an image, if they use the pinterest bookmarklet instead of using a pin it button that I specifically install, all they see is a bunch of blank boxes that show the image sizes and say pin it. No images. Any idea what I am doing wrong? I use Genesis Prose on my site. I’m an obvious newbie to the blogosphere. You’re a smart guy. I’m desperate for a solution. Thanks!!!
Hm, I honestly don’t know – perhaps set your image to be the Featured Image in your WP backend?
Hi Brian,
Thanks so much for this post, this is just what I needed.
How would I change the function to automatically grab the post title to use as the pin description? I have this function hooked to the Genesis Featured Widget Amplified plugin/widget in my sidebar:
Thanks!
Hm, honestly don’t know the answer to this one. If you post this over on the StudioPress forums someone there might be able to help.
I love how easy this was to install. Will the counter pick up on the number of times a post has already been pinned? If not automatically, is there a way to do this? I’m transferring from blogger to wordpress. My posts have already transferred, but links have not yet been redirected if that makes any difference.
Yes, it certainly should as it’s using the code taken directly from the Pinterest API servers.
Okay, I thought I had it figured out, but obviously I don’t since I can’t seem to get the button to show up. I considered the plugin, but it places the code after my Link Within thumbnails. Here are some questions I have:
1. When you say “create a file named single.php” what type of file are you referring to?
2. How do I “upload it to your child theme’s directory on your server?”
3. Does it automatically appear once I upload or are their additional steps?
Sorry, I’m such a WordPress newbie that I can’t even follow instructions
Or, if it’s easier, do you know of a way to change the location of the Pin it plugin?
Thanks for the info Brian! Out of curiosity, why put this into single.php instead of just adding it to functions.php?
You can do it in either, actually – just a matter of preference.
Brian,
How do I add the social buttons at the top and bottom of the post like you have on this post?
Just replied to your other comment with the code necessary.
Hi Brian,
hi can i post an image on pinterest from html like the sharer.php of facebook ?
I’ve a web site with a lot of image ad i have click on a with my styles (no iframe) to post it.
Nice! I know next to zero about css and even I was able to make this work on a custom theme built for me on Genesis. Thank you.
Hi Brian,
Clearly I am missing something and I’ve been racking my brains for days now. I have been able to add it using the single.php file but I have not been able to line it up with my other social sharing buttons which are powered by Add This.
Please could you help!
Here is the link: http://www.holisticsquid.com/white-chocolate-bark-with-pistachios-and-cranberries/
You will definitely be my hero!
Are you talking about the buttons that float off to the left of your post?
Hi Brian,
Yes, I am, thanks so much for the reply.
I am also trying to get the functionality of specifying which image the user posts to Pinterest from the post but so far haven’t had any luck with it – if you have any ideas?
I’m trying to make it work like this: http://www.foodrenegade.com/3-ways-reduce-your-childs-exposure-pesticides/
Thanks!
Hi Brian, how would I put this inline inside of an existing custom function? I have four custom buttons: FB, Twitter, G+ and Pinterest – at the bottom of each post. I’ve saved a spot with a but can’t find code that will work properly there. Would you mind taking a look?
http://daze.theblogmaven.com
Thank you!
Jeni
Oops, WordPress took out the HTML I wrote in my comment above. It should have said, “I saved a spot with a div id”
Switch to Jetpack.
Yes, but I’m going for the “one less plugin” approach you mentioned above.
It’s cool – I figured it out. Hope you’re enjoying the same springtime weather we are!
So I had this added to the Genesis Featured Widget Amplified widget back in September (see my comment above). A month or so ago the counts on the pin button stopped working. Any ideas why?