Skip to content

Instantly share code, notes, and snippets.

@thetwopct
Last active January 21, 2019 09:29
Show Gist options
  • Save thetwopct/05343a770b9b5a535184f62261412da1 to your computer and use it in GitHub Desktop.
Save thetwopct/05343a770b9b5a535184f62261412da1 to your computer and use it in GitHub Desktop.
Quick and dirty PHP share
<?php
$name = "Company Name"; // can include @handle here too
$title = "My amazing page";
// gets current domain and page
$currentDomain = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
// creates the share links
$twitterURL = 'https://twitter.com/intent/tweet?text='.$title.'&amp;url='.$currentDomain.'&amp;via='.$name;
$facebookURL = 'https://www.facebook.com/sharer/sharer.php?u='.$currentDomain;
?>
<h3>Share</h3>
Share URL: <?php echo $currentDomain; ?>
<br>
<a target="_blank" href="<?php echo $facebookURL; ?>">Share on Facebook</a>
<br>
<a target="_blank" href="<?php echo $twitterURL; ?>">Share on Twitter</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment