Skip to content

Instantly share code, notes, and snippets.

@Willem-Siebe
Last active August 29, 2015 14:00
Show Gist options
  • Save Willem-Siebe/11351787 to your computer and use it in GitHub Desktop.
Save Willem-Siebe/11351787 to your computer and use it in GitHub Desktop.
Loads the Pinterest JavaScript asynchronously. I add this to my WordPress website with wp_head, but you can copy and paste this snippet anywhere on your page. You only need to load this script once per page, no matter how many buttons or widgets you use. See: https://developers.pinterest.com/pin_it/. I also added a line to set the data-pin-hover…
// Add Pinterest Javascript to your website, see https://gist.github.com/Willem-Siebe/11351787.
function wsis_add_pinterest_script() {
?>
<script type="text/javascript">
(function(d){
var f = d.getElementsByTagName('SCRIPT')[0], p = d.createElement('SCRIPT');
p.type = 'text/javascript';
p.async = true;
p.setAttribute('data-pin-hover', true);
p.src = '//assets.pinterest.com/js/pinit.js';
f.parentNode.insertBefore(p, f);
}(document));
</script>
<?php
}
add_action( 'wp_head', 'wsis_add_pinterest_script' );
@Willem-Siebe
Copy link
Author

On 12-04-2014 I discovered that when you are logged in with WordPress, there is a offset for the pin it button.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment