Skip to content

Instantly share code, notes, and snippets.

@jdevalk
Created April 16, 2012 10:16
Show Gist options
  • Save jdevalk/2397515 to your computer and use it in GitHub Desktop.
Save jdevalk/2397515 to your computer and use it in GitHub Desktop.
Pinterest button shortcode
<?php
// Usage [pin img="<url>" title="<title>"]
function yoast_pinterest_shortcode( $atts ) {
extract( shortcode_atts( array(
'url' => get_permalink(),
'img' => '',
'title' => get_the_title(),
'align' => 'alignright'
), $atts ) );
return '<div class="'.esc_attr( $align ).'"><a href="http://pinterest.com/pin/create/button/?url='.esc_attr( urlencode($url) ).'&media='.esc_attr( urlencode($img) ).'&description='.esc_attr( urlencode( $title) ).'" class="pin-it-button" count-layout="vertical"><img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" /></a><script type="text/javascript" src="//assets.pinterest.com/js/pinit.js"></script></div>';
}
add_shortcode( 'pin', 'yoast_pinterest_shortcode' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment