I'm trying to create custom social share buttons for my website but I'n running into issues that the current page title and url are not being pulled properly to be shared with the social networks.
example of my code looks like:
<a class="share-btn twitter-btn twitter-sharer-button" id="ref_tw" href="https://twitter.com/intent/tweet?title=<?php echo $title; ?>&url=<?php echo urlencode($share_url);?>&via=Udamonia" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=no,scrollbars=no,height=400,width=600');return false;"></a>
Any help or a point in the right direction is greatly appreciated.
Thanks!
Use Javascript in the onclick event to grab the
document.title
anddocument.location.href
which you then append to the share URL and subsequently set the new URL to.So your onclick attribute would look like: