Created
April 17, 2017 19:42
-
-
Save AustinGil/dea935360ee86763d023338ad46acfa2 to your computer and use it in GitHub Desktop.
Create social sharing buttons in WordPress that open popup for sharing
This file contains hidden or 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
/** SOCIAL MEDIA SHARES */ | |
var shareBtns = document.querySelectorAll('.social-share-btns a'); | |
shareBtns.forEach( function(btn) { | |
btn.addEventListener('click', function(e) { | |
e.preventDefault(); | |
var width = 575, height = 400, | |
left = (document.documentElement.clientWidth / 2 - width / 2), | |
top = (document.documentElement.clientHeight - height) / 2, | |
url = e.target.href, | |
opts = 'status=1,resizable=yes' + | |
',width=' + width + ',height=' + height + | |
',top=' + top + ',left=' + left; | |
window.open(url, '', opts); | |
}); | |
}); | |
/** END SOCIAL MEDIA SHARES */ |
This file contains hidden or 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
<div class="social-share-btns"> | |
<?php // Make sure you are in the loop | |
$this_url = wp_get_shortlink(); ?> | |
<ul class="list-inline"> | |
<li class="twitter"> | |
<a href="https://twitter.com/intent/tweet?source=<?php echo urlencode ($this_url); ?>&text=<?php echo get_the_title() . ': ' . urlencode ($this_url); ?>" class="xicon-twitter" rel="noreferrer" title="Twitter">Twitter</a> | |
</li> | |
<li class="facebook"> | |
<a href="https://www.facebook.com/sharer/sharer.php?u=<?php echo urlencode ($this_url); ?>&t=<?php echo get_the_title(); ?>" class="xicon-facebook" rel="noreferrer" title="Facebook">Facebook</a> | |
</li> | |
<li class="linkedin"> | |
<a href="http://www.linkedin.com/shareArticle?mini=true&url=<?php echo urlencode ($this_url); ?>&title=<?php echo get_the_title(); ?>&summary=<?php echo urlencode ( get_the_excerpt() ); ?>" class="xicon-linkedin" rel="noreferrer" title="LinkedIn">LinkedIn</a> | |
</li> | |
</ul> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment