Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created December 28, 2016 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/6ab6b7c9a2175eb69767b1813bd39f17 to your computer and use it in GitHub Desktop.
Save billerickson/6ab6b7c9a2175eb69767b1813bd39f17 to your computer and use it in GitHub Desktop.
<?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>');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment