Created
July 8, 2014 14:34
-
-
Save jaredatch/027f611dda00431253ab to your computer and use it in GitHub Desktop.
Dynamically create Pinterest Pin button for content images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Inline javascript | |
* | |
* @since 1.0.0 | |
*/ | |
function ja_pinterest_button() { | |
?> | |
<script type="text/javascript"> | |
jQuery(document).ready(function($) { | |
if ( $( window ).width() > 700 ) { | |
$('.entry-content img').each(function(index, el) { | |
if ( !$(this).hasClass('no-pin') && !$(this).hasClass('alignleft') && !$(this).hasClass('alignright') ) { | |
media = $(this).prop('src'); | |
link = '<a href="http://pinterest.com/pin/create/button/?url=<?php echo urlencode( get_permalink() ); ?>&media=' + media + '&description=<?php echo urlencode( get_the_title() ); ?>" class="pin-it-button">Pin</a>'; | |
$(this).wrap('<div class="pin-image-wrapper"></div>').after(link); | |
} | |
}); | |
} | |
}); | |
</script> | |
<?php | |
} | |
add_action( 'wp_footer', 'ja_pinterest_button' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment