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

I am trying to find a short code that will allow me to add a β€œPin It” (Pinterest) link, a text link to my Wordpress blog. I just need a text link. I do not want to use the graphic button on which they provide the code, which makes this complex process.

This is very easy to do with Facebook and Twitter. For instance:

<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 how to use a similar line of code for Pinterest? Any recommendations are appreciated.

+6
source share
5 answers

This is what I did on my site.

 /*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 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.

+3
source

I use: ( source )

in the .php function:

  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% 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> 
+2
source

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> 

HTML example:

 <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> 
+1
source

if I carefully consider the generated button :

There is an <img> tag there:

Perhaps this is what you want:

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

And here is how you do it using the 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> 
0
source

Convert @AllanT response to shortcode.

Usage: [pinterest-link title="HREF TITLE" text="ANCHOR TEXT"]
The title and text attributes 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; } 
0
source

Source: https://habr.com/ru/post/913688/


All Articles