Glyph
Glyph

Reputation: 97

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

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.

Upvotes: 6

Views: 8402

Answers (5)

meck373
meck373

Reputation: 1124

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>

Upvotes: 2

brasofilo
brasofilo

Reputation: 26075

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;
}

Upvotes: 0

morksinaanab
morksinaanab

Reputation: 732

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>

Upvotes: 1

AllanT
AllanT

Reputation: 961

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.

Upvotes: 3

ariefbayu
ariefbayu

Reputation: 21979

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>

Upvotes: 0

Related Questions