Pin It on Images

<?php

/**
 * Scripts 
 *
 */
function ea_scripts() {
  	wp_enqueue_script( 'pinit', '//assets.pinterest.com/js/pinit.js', false, false, true );
}
add_action( 'wp_enqueue_scripts', 'ea_scripts' );

/**
 * Script Loader
 *
 */
function ea_script_loader( $tag, $handle ) {
	if( 'pinit' == $handle )
		$tag = str_replace( ' src', ' async="async" src', $tag );
	return $tag;
}
add_filter( 'script_loader_tag', 'ea_script_loader', 10, 2 );
jQuery(function($){

  	// Pinterest PinIt
	$('.page-header .wrap, .wp-caption').each(function(){
		margin_top = 42;
		if( $(this).find('.wp-caption-text').length ) {
			margin_top += $(this).find('.wp-caption-text').height() + 35;
		}
		$(this).append('<span class="pinit" style="margin-top: -' + margin_top + 'px; margin-right: 10px; float: right;"><a data-pin-do="buttonBookmark" data-pin-tall="true" data-pin-round="true" data-pin-save="false" href="https://www.pinterest.com/pin/create/button/"><img src="//assets.pinterest.com/images/pidgets/pinit_fg_en_round_red_32.png" /></a></span>');
	});

});

Bill Erickson

Bill Erickson is the co-founder and lead developer at CultivateWP, a WordPress agency focusing on high performance sites for web publishers.

About Me
Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk