michaelmcgurk
michaelmcgurk

Reputation: 6509

Pinterest Share HTML Link error

I am having an issue with my 'Share to Pinterest' link. I have a JSFiddle if it helps.

Basically the url portion isn't being carried into my new pop up window :'-(

Here's my Javascript too:

$('.share.pinterest').click(function(e){
        e.preventDefault();

        var target = $(this),
            url = target.data('url') || "";

        var width  = 575,
            height = 400,
            left   = ($(window).width()  - width)  / 2,
            top    = ($(window).height() - height) / 2,
            gplus    = 'https://www.pinterest.com/pin/create/button/?url='+ url + '',
            opts   = 'status=1' +
                     ',width='  + width  +
                     ',height=' + height +
                     ',top='    + top    +
                     ',left='   + left;


        window.open(gplus, 'Pinterest', opts);

    });

Many thanks for any help & guidance with this issue.

Upvotes: 1

Views: 1019

Answers (2)

michaelmcgurk
michaelmcgurk

Reputation: 6509

<a href="http://www.pinterest.com/pin/create/button/?url=<?php the_permalink(); ?>&media=<?php if(function_exists('the_post_thumbnail')) echo wp_get_attachment_url(get_post_thumbnail_id()); ?>&description=<?php echo get_the_title(); ?> - <?php echo get_permalink(); ?>" id="pinterest" target="_blank">Pinterest Pin It</a>

Upvotes: 0

Control Freak
Control Freak

Reputation: 13243

Encode your url parameter using encodeURIComponent()

gplus = 'https://www.pinterest.com/pin/create/button/?url='
        + encodeURIComponent(url)

Edit:

It's because pinterest is redirecting your url to this:

https://www.pinterest.com/join/?next=/pin/create/button/

During this redirect that is done by pinterest, it encodes the url for you and changes the static url you entered to a querystring version. So you may want to submit the request like this instead:

https://www.pinterest.com/join/?next=/pin/create/button/&url=

Upvotes: 2

Related Questions