megwoo
6/30/2015 - 7:04 PM

Codes for manually sharing on Facebook, Twitter, Google+ and email

Codes for manually sharing on Facebook, Twitter, Google+ and email

// php encoding for URL
$shareUrl = htmlspecialchars(urlencode(html_entity_decode(get_permalink(), ENT_COMPAT, 'UTF-8')), ENT_COMPAT, 'UTF-8');

// php encoding for title
$shareTitle = htmlspecialchars(rawurlencode(html_entity_decode("#surfventures - " . get_the_title(), ENT_COMPAT, 'UTF-8')), ENT_COMPAT, 'UTF-8');


// share URLS
<div class="social_share">
	<a class="twitter_share" href="javascript:PopUp('https://twitter.com/intent/tweet?text=<?php echo $shareTitle; ?>&amp;url=<?php echo $shareUrl; ?>&amp;hashtags=surfventures&amp;via=carapacewetsuit');" target="_blank" title="Twitter">Twitter</a>
	<a class="facebook_share" href="javascript:PopUp('http://www.facebook.com/sharer.php?u=<?php echo $shareUrl; ?>');" target="_blank" title="Facebook">Facebook</a>
	<a class="google_share" href="javascript:PopUp('https://plus.google.com/share?url=<?php echo $shareUrl; ?>');" target="_blank" title="Google+">Google Plus</a>
	<a class="email_share" href="mailto:?subject=<?php echo $shareTitle; ?>&amp;body=<?php echo $shareUrl; ?>" title="Email">Email</a>						
</div>


// script for pop-up
<script language="JavaScript" charset="UTF-8">
<!--
function PopUp(URL) {
	var encodedURL;
	encodedURL = encodeURI( URL );
	encodedURL = encodedURL.replace("#", "%23");
	window.open(encodedURL, 'Windowname', 'width=450, height=300, toolbar=0, scrollbars=1 ,location=0 ,statusbar=0,menubar=0, resizable=0');
}
//-->
</script>