The meaning of adding dynamic Pinterest button, is the option to “Pin” the current page URL. The pinned image may be default, like your logo or image from the page (predefined). Here comes the code:
Adding “Pin It” button to your PHP page or WP theme:
1. Copy this code to your page only once, directly above the closing </BODY> tag:
<script type="text/javascript" src="//assets.pinterest.com/js/pinit.js"></script>
2. Add this code to your page, right where you want the button to appear:
<a href="http://pinterest.com/pin/create/button/?url=<?php echo 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; ?>&media=HTTP://WWW.EXAMPLE.COM/YOUR-LOGO-IMAGE.JPG&description=my website tagline" count-layout="horizontal"><img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" /></a>
To make this button work on ASP/NET pages:
<a href="http://pinterest.com/pin/create/button/?url=<%response.write http://: & request.ServerVariables(“server_name”) & request.ServerVariables(“request_uri”) %>&media=HTTP://WWW.EXAMPLE.COM/YOUR-LOGO-IMAGE.JPG&description=my website tagline" count-layout="horizontal"><img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" /></a>
Dynamic button, that will “pin” specific WordPress post URL, post title and the featured image
1. Copy this code to your page only once, directly above the closing </BODY> tag:
<script type="text/javascript" src="//assets.pinterest.com/js/pinit.js"></script>
2. Add this one, right where you want the button to appear:
<a href="http://pinterest.com/pin/create/button/?url=<?php echo 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];?>&media=<?php if (has_post_thumbnail( $post->ID ) ): ?><?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?><?php echo $image[0]; ?><?php endif; ?>&description=<?php the_title(); ?>" count-layout="horizontal"><img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" /></a>
Resources & Credits:
1. Default button code by Pinterest
2. PHP ideas by Yoni Greenberg
3. ASP by Eyal Berman
4. Retrieving featured image URL by Styledev
5. The idea comes from dynamic FaceBook Like button