Link to "pin it" on pinterest without generating a button
Asked Answered
C

7

127

I have a page with tens or hundreds of posts, each one with social buttons. I just can't generate all the buttons for each url: it is too slow (facebook, g+, twitter, pinterest... for hundreds of links). So, instead of the facebook share button to be generated on the fly, I use a simple img pointing to

https://www.facebook.com/sharer.php?u=${url_of_current_post}&t=

When the user clicks on it, a popup window opens with content generated by facebook.

How can I do it for Pinterest? I only find around code to generate the button, but I would like to avoid js at all if possible. Is there something like the following?

http://pinterest.com/pinthis?url=${url_of_current_post}

Please do not try to make me use the js button, thanks.

Cwmbran answered 21/5, 2012 at 17:45 Comment(0)
B
85

If you want to create a simple hyperlink instead of the pin it button,

Change this:

http://pinterest.com/pin/create/button/?url=

To this:

http://pinterest.com/pin/create/link/?url=

So, a complete URL might simply look like this:

<a href="//pinterest.com/pin/create/link/?url=http%3A%2F%2Fwww.flickr.com%2Fphotos%2Fkentbrew%2F6851755809%2F&media=http%3A%2F%2Ffarm8.staticflickr.com%2F7027%2F6851755809_df5b2051c9_z.jpg&description=Next%20stop%3A%20Pinterest">Pin it</a>

Bagel answered 21/8, 2013 at 2:31 Comment(8)
I much prefer to make my own links. Is this still working, or have they changed it?Refulgent
The accepted answer will generate a button if you have another pinterest button (and the pinit.js script loaded). Changing the url to have 'link' instead of 'button' will allow you to have a pinterest button in your footer and a custom pinterest link somewhere on your page. This should be the accepted answer.Dippy
Thank you for your answer, exactly what I was looking for. This should be the right answer in my opinion :)Are
I upvoted this answer, but later found that pinterest throws an error when trying to pin: Parameter 'method' (value link) is not one of unknown, uploaded, scraped, bookmarklet, email, iphone, button, ipad, android, android_tablet, api_sdk, extension, api_other, bad.. The solution is to keep the url as button but ignore the pinterest script. see https://mcmap.net/q/175858/-custom-pinterest-button-for-custom-url-text-link-image-or-bothAmine
this will not work, as @Amine said: it will result in the error pinterest parameter method value link is not one of unknown, uploaded, scraped, bookmarklet, email, iphone, button, ipad, android, android_tablet, api_sdk, extension, api_other, api_bulk_upload, adtech, directpartner, martech, button_external, bad. Apparently the parameter after create must be one of these possibilities.Flexed
does not throw an error as of now :P using as a property listing share link: http://pinterest.com/pin/create/link/?url=URL&media=COVERIMAGE&description=ADDRESSIntelligent
@Intelligent What should be defined in param "media" and "description"? Is there an official documentation you could link?Gabbert
New final Url to post is https://pinterest.com/pin-builder/?url=YOUR-URL&media=IMAGE-URL&description=YOUR-DESCRIPTIONMelancholic
H
189

The standard Pinterest button code (which you can generate here), is an <a> tag wrapping an <img> of the Pinterest button.

If you don't include the pinit.js script on your page, this <a> tag will work "as-is". You could improve the experience by registering your own click handler on these tags that opens a new window with appropriate dimensions, or at least adding target="_blank" to the tag to make it open clicks in a new window.

The tag syntax would look like:

<a href="http://pinterest.com/pin/create/button/?url={URI-encoded URL of the page to pin}&media={URI-encoded URL of the image to pin}&description={optional URI-encoded description}" class="pin-it-button" count-layout="horizontal">
    <img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" />
</a>

If using the JavaScript versions of sharing buttons are ruining your page load times, you can improve your site by using asynchronous loading methods. For an example of doing this with the Pinterest button, check out my GitHub Pinterest button project with an improved HTML5 syntax.

Hayse answered 26/6, 2012 at 16:52 Comment(5)
Great answer, thanks! Also please see our page on developer.pinterest.com, here: developers.pinterest.com/pin_itDiscontinuous
The Pin It widget builder business.pinterest.com/widget-builder/#do_pin_it_button is also useful for getting some sample code that you can then customise programatically.Hilleary
@KentBrewster - For what it's worth, I ended up here with the same question after visiting your page. The info it has is all great, but it doesn't talk about the URL parameters or that the URL can be used without javascript (under the context of creating buttons on the fly) like facebook and twitter equivalent pages do.Neri
My urlencode on the description is a bit janky. Any idea why? Example: "At this point, I&amp;#8217;m just going to copy &amp;amp; paste from another post because&amp;#8230; time." -- obviously less than ideal.Overall
The above answer works fine if user is already logged-in in pinterest otherwise it just stays in the pinterest home page even after successful login. Any solutions?Weingarten
B
85

If you want to create a simple hyperlink instead of the pin it button,

Change this:

http://pinterest.com/pin/create/button/?url=

To this:

http://pinterest.com/pin/create/link/?url=

So, a complete URL might simply look like this:

<a href="//pinterest.com/pin/create/link/?url=http%3A%2F%2Fwww.flickr.com%2Fphotos%2Fkentbrew%2F6851755809%2F&media=http%3A%2F%2Ffarm8.staticflickr.com%2F7027%2F6851755809_df5b2051c9_z.jpg&description=Next%20stop%3A%20Pinterest">Pin it</a>

Bagel answered 21/8, 2013 at 2:31 Comment(8)
I much prefer to make my own links. Is this still working, or have they changed it?Refulgent
The accepted answer will generate a button if you have another pinterest button (and the pinit.js script loaded). Changing the url to have 'link' instead of 'button' will allow you to have a pinterest button in your footer and a custom pinterest link somewhere on your page. This should be the accepted answer.Dippy
Thank you for your answer, exactly what I was looking for. This should be the right answer in my opinion :)Are
I upvoted this answer, but later found that pinterest throws an error when trying to pin: Parameter 'method' (value link) is not one of unknown, uploaded, scraped, bookmarklet, email, iphone, button, ipad, android, android_tablet, api_sdk, extension, api_other, bad.. The solution is to keep the url as button but ignore the pinterest script. see https://mcmap.net/q/175858/-custom-pinterest-button-for-custom-url-text-link-image-or-bothAmine
this will not work, as @Amine said: it will result in the error pinterest parameter method value link is not one of unknown, uploaded, scraped, bookmarklet, email, iphone, button, ipad, android, android_tablet, api_sdk, extension, api_other, api_bulk_upload, adtech, directpartner, martech, button_external, bad. Apparently the parameter after create must be one of these possibilities.Flexed
does not throw an error as of now :P using as a property listing share link: http://pinterest.com/pin/create/link/?url=URL&media=COVERIMAGE&description=ADDRESSIntelligent
@Intelligent What should be defined in param "media" and "description"? Is there an official documentation you could link?Gabbert
New final Url to post is https://pinterest.com/pin-builder/?url=YOUR-URL&media=IMAGE-URL&description=YOUR-DESCRIPTIONMelancholic
B
13

I had the same question. This works great in Wordpress!

<a href="//pinterest.com/pin/create/link/?url=<?php the_permalink();?>&amp;description=<?php the_title();?>">Pin this</a>
Balance answered 12/2, 2014 at 22:12 Comment(0)
I
3

For such cases, I found very useful the Share Link Generator, it helps creating Facebook, Google+, Twitter, Pinterest, LinkedIn share buttons.

Irvinirvine answered 6/8, 2015 at 8:52 Comment(0)
B
2

I Found some code for wordpress:

 <script type="text/javascript">

    function insert_pinterest($content) {
        global $post;
        $posturl = urlencode(get_permalink()); //Get the post URL
        $pinspan = '<span class="pinterest-button">';
     $pinurl = '';
     $pinend = '</span>';
        $pattern = '//i';
        $replacement = $pinspan.$pinurl.'$2.$3'.$pindescription.$pinfinish.''.$pinend;
        $content = preg_replace( $pattern, $replacement, $content );
        //Fix the link problem
        $newpattern = '/<span class="pinterest-button"><\/a><\/span><\/a>/i';
     $replacement = '';
     $content = preg_replace( $newpattern, $replacement, $content );
     return $content;
    }
    add_filter( 'the_content', 'insert_pinterest' );

    </script>

Then you put the following in your PHP:

<?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(); ?>">Pin It</a>
Baldhead answered 6/8, 2012 at 15:20 Comment(0)
L
2

So you want the code to the pin it button without installing the button? If so just paste this code in the place of the url of the page you're pinning from. It should function as a pin it button without the button.

javascript:void((function(){var%20e=document.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('charset','UTF-8');e.setAttribute('src','http://assets.pinterest.com/js/pinmarklet.js?r='+Math.random()*99999999);document.body.appendChild(e)})());

Launderette answered 16/8, 2012 at 8:35 Comment(3)
This worked for me, but 2 questions. How can you maintain the popup? Also, what does the random math do?Rugg
It's Pinterest's official code from their 'bookmarklet'. It's normally used as a link you save to your bookmarks and can click on any website you visit in order to bring up a Pinterest dialogue, but it works fine this way too, and is easy to implement.Hagride
They pretty specifically tell you not to do this in the API docs. Just because you can, doesn't mean you should.Overall
F
0

You can create a custom link as described here using a small jQuery script

$('.linkPinIt').click(function(){
    var url = $(this).attr('href');
    var media = $(this).attr('data-image');
    var desc = $(this).attr('data-desc');
    window.open("//www.pinterest.com/pin/create/button/"+
    "?url="+url+
    "&media="+media+
    "&description="+desc,"_blank","top=0,right=0,width=750,height=320");
    return false; 
});

this will work for all links with class linkPinItwhich have the image and the description stored in the HTML 5 data attributes data-image and data-desc

<a href="https%3A%2F%2Fwww.flickr.com%2Fphotos%2Fkentbrew%2F6851755809%2F" 
   data-image="https%3A%2F%2Fc4.staticflickr.com%2F8%2F7027%2F6851755809_df5b2051c9_b.jpg" 
   data-desc="Title for Pinterest Photo" class="linkPinIt">
    Pin it!
</a> 

see this jfiddle example

Flexed answered 31/3, 2015 at 15:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.