Create jQuery Pinterest Pin It Plugin

Written by Kevin Liew on 23 Jul 2012
105,421 Views • Tutorials


Pinterest has been growing to become one of the famous social media website. It allows us organize and share all the beautiful things we find on the web. I found it very resourceful when looking for interior design, decoration and other inspirations.

As you might have noticed, nowadays, pinterest Pin count button can be found in most design websites, they also released a bookmarklet that scan a webpage for images and allow you to pin it easily. However, sometimes you might find it's not that convenience when the page contain more than 30 images. It takes a while to find the image. As a result, I created this plugin that allow you to pin the image straight away.

This plugin looks for all images, and wrap it inside a container that come with a pinterest Pin it button. So, your visitor just have to hover above the image they want, and pin it straight away. It's a simple plugin.


There isn't any HTML code, basically you just need to include the CSS and Javascript files:

<script type="text/javascript" src="//"></script>
<script type="text/javascript" src="js/jquery.pinit.js"></script>
<script type="text/javascript">
$(function () {




You can customize the plugin with CSS. I have made 2 semi transparent images (white and black), so free feel to swap them. The CSS is quite simple, most of the styles are for the buttons.

.pinit {


/* pin it overlay style */
.pinit .pinit-overlay {
	background:transparent url('../images/semi-white.png') repeat 0 0;

/* button style, and center it */
.pinit .pinit-overlay a {
	margin:-10px 0 0 -21px;
	background:transparent url('../images/pinit-button.png') no-repeat 0 0;

.pinit .pinit-overlay a:hover {
	background-positon: 0 -21px;

.pinit .pinit-overlay a:active {
	background-position: 0 -42px;


There isn't any complex stuff in javascript section. Basically, we are making a plugin that wrap each of the images with a .pinit span and add some HTML that will do the overlay effect with PinIt button. PinIt button is linking to pinterest's Pin URL:{MEDIA_URL}'&url={URL}&is_video={IS_VIDEO}&description={DESC}

    //Attach this new method to jQuery
        pinit: function(options) {
			var defaults = {
				wrap: '<span class="pinit"/>',
				pageURL: document.URL
 			var options = $.extend(defaults, options);
			var o = options; 
            //Iterate over the current set of matched elements
            return this.each(function() {
             	var e = $(this),
             		pi_media ='media') ?'media') : e[0].src,
             		pi_url = o.pageURL,
             		pi_desc = e.attr('title') ? e.attr('title') : e.attr('alt'),
             		pi_isvideo = 'false';
             		bookmark = '' + encodeURI(pi_media) + '&url=' + encodeURI(pi_url) + '&is_video=' + encodeURI(pi_isvideo) + '&description=' + encodeURI(pi_desc);
				var eHeight = e.outerHeight();				
             		e.after('<span class="pinit-overlay" style="height: ' + eHeight + 'px"><a href="' + bookmark + '" class="pinit-button">Pin It</a></span>');
				$('.pinit .pinit-button').on('click', function () {$(this).attr('href'), 'Pinterest', 'width=632,height=253,status=0,toolbar=0,menubar=0,location=1,scrollbars=1');				
					return false;
				$('.pinit').mouseenter(function () {
				}).mouseleave(function () {




That's about it. Simple plugin made with jQuery in just half an hour. I have tested it across different browsers (Chrome, Firefox, IE 7+) and they work fine. Have fun Pinning.

Demo Download
Join the discussion

Comments will be moderated and rel="nofollow" will be added to all links. You can wrap your coding with [code][/code] to make use of built-in syntax highlighter.

Muskie 11 years ago
I keep playing with your JavaScript. I got it to work here:

But I keep modifying it. It definitely will take work to use it with Isotope, but also it seems like it doesn't always find the alt and/or title attribute on this test:

It appears if you have something like #target in the URL it messes with the JavaScript, also given the choice between the alt and title it prefers title which is I guess fine.

Jaime Vallejo 10 years ago
Hi. Excellent plugin and tutorial. Only one comment. I have better result with event load instead event ready. I suppose that is because sometimes jquery can't know image height without having loaded it. (Excuse my bad english :P)

DeVe 10 years ago
Awesome! Thanks a lot!
Laz Davila 10 years ago
Great script and css - thanks.
Just in case anyone is having problems with responsive layouts, this simple fix will make the images resize correctly:

.pinit {
Bijal 9 years ago
Hi Kevin,

I want to do some functionality based on pin it button response. Can you please guide me how can i achieve this function.
Etienne 9 years ago
hi kevin,

I have to apply your pluggin only on certain images of the page , I tried to change the script , and the html , but with no success , i have two different <div> that contains the pictures i want to pin :

- <div class="exibition">
<img .../>

-<div class="Pro">

how can I apply the pin it button to these img only ?

thank you anyway for this pluggin that work perfectly !
jo-anne 9 years ago
Hi Kevin,

I downloaded your plugin on my blog but the spaces between the photos were altered/deleted. Is there a way to fix this problem?
carla 9 years ago
Hi! After looking all over the web I found your site. Thank you for sharing your knowledge!
My question is: is it possible to apply it ver Squarespace, where de jquery is already pre-configured? I only want to change the button for some custom. Tks!
Richard 8 years ago
Thanks for article, but it doesn't seem to work on my wordpress 4.2.4 blog.

In footer.php I didn't place your googleapis jquery link as my site already calls in header.php and some plugins call jquery lib as well, something I have to figure out how to get rid of as it's adding extra https calls to

Thanks anyway.
Kris 8 years ago
Is this plugin meant to work on mobile devices if you have the Pinterest app installed? I found on my phone/ipad if I do NOT have the Pinterest app installed, the plugin opens Pinterest in a browser as expected. But if I have the app installed, I'm not redirected to the app.
Kris 8 years ago
Does this integrate with the Pinterest app on iOS? Namely, can I click on the pinit button and be taking to the Pinterest app to a place where I would pin the image? It seems when I do it, it just takes me to the Pinterest app but I can't pin the image to my board.