Pinterest 'Pin it' short code for text only link in wordpress blog
Asked Answered
S

5

6

I am trying to find a short code that will enable me to add a 'Pin It' (Pinterest), text link to my wordpress blog. I just want a text link only. I don't want to use the graphical button they provide the code for, which is what makes this tricky.

It's very simple to do with Facebook and Twitter. For example:

<a href="http://www.facebook.com/share.php?u=<?php echo get_permalink() ?>" title="Share on Facebook" target="_blank">Facebook,</a>

<a href="http://twitter.com/home?status=Currently reading <?php the_permalink(); ?>" title="Share on Twitter" target="_blank">Twitter,</a>

Does anyone know a way to use a similar line of code for Pinterest? Any guidance is appreciated.

Spock answered 20/4, 2012 at 3:56 Comment(0)
B
3

This is what I've done on a site of mine.

/*Stuff for Pinterest*/
    //getting the permalink
$postpermalink = urlencode( get_permalink() );

    //getting the thumbnail
$imageurl = urlencode( wp_get_attachment_url( get_post_thumbnail_id($post->ID) ) );
/*End of Pinterest*/

Then the html:

<a target="blank" href="http://pinterest.com/pin/create/button/?url=<?php echo $postpermalink ?>&media=<?php echo $imageurl ?>" title="Pin This Post">Pin</a>

Hope this helps.

Brahmanism answered 17/11, 2012 at 1:49 Comment(0)
S
2

I use: (source)

in the function.php:

    function pinterest_post_page_pin_no_count() {
    global $post;
    /* HORIZONTAL NO-COUNTER PINTEREST BUTTON */
    printf( '<div class="pinterest-posts"><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( get_post_meta($post->ID, 'thesis_post_image', true) ) );
    }
    add_shortcode( 'thesis_hook_before_post_box', 'pinterest_post_page_pin_no_count' );

in the %template-name%.php

 <?php echo do_shortcode("[thesis_hook_before_post_box]"); ?>   

or just (source)

<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>
Secondclass answered 18/5, 2014 at 18:22 Comment(0)
E
1

You can use a similar approach as follows:

<a target="_blank" href="http://pinterest.com/pin/create/button/?url=<?php the_permalink(); ?>&amp;media=<?php echo $image->guid;?>&amp;description=<?php echo rawurlencode(get_the_title()); ?>">Pinterest,</a>

Example HTML:

<a target="_blank" href="http://pinterest.com/pin/create/button/?url=http://www.google.&amp;media=http://www.google.co.id/images/srpr/logo3w.png&amp;description=Google Search Engine" >Pinterest,</a>
Exceptionable answered 22/11, 2012 at 9:3 Comment(0)
E
0

if I look closely at the generated button:

There's an <img> tag:

Maybe this is what you want:

<a href="http://pinterest.com/pin/create/button/" class="pin-it-button" count-layout="horizontal">pin it!</a>

And this is how you do it using server code:

<a href="http://pinterest.com/pin/create/button/?url={the URL you want to pin}&media={image URL assiciated to the URL}&description={image or URL description}" class="pin-it-button" count-layout="horizontal">pin it!</a>
Earthquake answered 20/4, 2012 at 4:17 Comment(4)
I don't think this works. The generated button code asks me to enter a URL and image name. However I need code that just pulls this information out of the page with php like those Facebook and twitter examples.Spock
I've tried this too, however it forces the button graphic to appear. I've tried creating a custom class for pin-it-button to hide it, but still no love. Surely it can't be that hard to just show a text only link??Spock
just a clarification: by saying it forces the button graphic to appear, does this mean that: (1) the button graphic is, pin graphic on your page or (2) the graphic on pin result page (on pinterest website)?Earthquake
No I mean the little pin graphic on my page. I don't want any graphics, just a plain text link.I'm still not having any luck working out a way to do this. It can't be that hard surely? I am trying everything and have spent hours trying to work this out. Does anyone possibly have any other leads on this?Spock
R
0

Converting @AllanT answer into a shortcode.

Usage: [pinterest-link title="HREF TITLE" text="ANCHOR TEXT"]
The attributes title and text are optional.

add_shortcode( 'pinterest-link', 'so_10240032_pinterest_text_link' );

function so_10240032_pinterest_text_link( $atts, $content = null )
{   
    $title = ( isset( $atts['title'] ) ) ? $atts['title'] : 'Pin This Post';
    $text  = ( isset( $atts['text'] ) )  ? $atts['text']  : 'Pin';

    $postpermalink = urlencode( get_permalink() );

    $imageurl = urlencode( 
        wp_get_attachment_url( 
            get_post_thumbnail_id( $post->ID ) 
        ) 
    );

    $html = 
        '<a target="blank" href="http://pinterest.com/pin/create/button/?url=' 
        . $postpermalink 
        . '&media='
        . $imageurl
        . '" title="'
        . $title 
        . '">'
        . $text 
        . '</a>';

    return $html;
}
Roister answered 28/11, 2012 at 18:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.