Skip to content

Instantly share code, notes, and snippets.

@MrImranJaved
Last active January 11, 2024 09:00
Show Gist options
  • Save MrImranJaved/423829024066a47a251e8375ff38ec49 to your computer and use it in GitHub Desktop.
Save MrImranJaved/423829024066a47a251e8375ff38ec49 to your computer and use it in GitHub Desktop.
<?php
// function to display the social media sharing links:
function bim_add_social_sharing_links(){
$html ='<div class="row chart-utils" style="margin: 20px 0 0 0; justify-content: start; gap: 20px;">
<a target="blank" onclick="facebooksharing();" class="facebook"><i class=" fa fa-facebook facebook" style="color: #2980b9;"></i></a>
<a target="blank" onclick="twittersharing();" class="twitter"><svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 512 512"><path d="M389.2 48h70.6L305.6 224.2 487 464H345L233.7 318.6 106.5 464H35.8L200.7 275.5 26.8 48H172.4L272.9 180.9 389.2 48zM364.4 421.8h39.1L151.1 88h-42L364.4 421.8z"></path></svg></a>
<a target="blank" onclick="redditsharing();" class="reddit"><i class=" fa fa-reddit reddit" style="color: #c0392b;"></i></a>
<a target="blank" onclick="linkedsharing();" class="linkedin"><i class=" fa fa-linkedin linkedin" style="color: #1e90ff;"></i></a>
<a target="blank" onclick="whatsappsharing();" class="whatsapp"><i class=" fa fa-whatsapp whatsapp" style="color: #2ecc71;"></i></a>
<a target="blank" onclick="telegramsharing();" class="telegram"><i class=" fa fa-telegram telegram" style="color: #2980b9;"></i></a>
</div>';
return $html;
}
?>
//Javascript functions
<script>
function facebooksharing(){
const pagetitle = document.querySelector('.title_single_area h1').innerHTML;
const reportexcerpt = jQuery('.post-inner p').text();
const link = encodeURI(window.location.href);
const msg = encodeURIComponent(reportexcerpt);
const title = encodeURIComponent(pagetitle);
const fb = document.querySelector('.facebook');
fb.href = `https://www.facebook.com/share.php?u=${link}`;
}
function twittersharing(){
const pagetitle = document.querySelector('.title_single_area h1').innerHTML;
const reportexcerpt = jQuery('.post-inner p').text();
const reporttext = reportexcerpt.substring(0,50);
const link = encodeURI(window.location.href);
const msg = encodeURIComponent(reporttext);
const title = encodeURIComponent(pagetitle);
let kw = pagetitle.split(' ');
const twitter = document.querySelector('.twitter');
twitter.href = `http://twitter.com/share?&url=${link}&text=${msg}&hashtags=${kw}`;
}
function redditsharing(){
const pagetitle = document.querySelector('.title_single_area h1').innerHTML;
const reportexcerpt = jQuery('.post-inner p').text();
const reporttext = reportexcerpt.substring(0,50);
const link = encodeURI(window.location.href);
const msg = encodeURIComponent(reporttext);
const title = encodeURIComponent(pagetitle);
const reddit = document.querySelector('.reddit');
reddit.href = `http://www.reddit.com/submit?url=${link}&title=${title}`;
}
function linkedsharing(){
const pagetitle = document.querySelector('.title_single_area h1').innerHTML;
const reportexcerpt = jQuery('.post-inner p').text();
const reporttext = reportexcerpt.substring(0,50);
const link = encodeURI(window.location.href);
const msg = encodeURIComponent(reporttext);
const title = encodeURIComponent(pagetitle);
const linkedIn = document.querySelector('.linkedin');
linkedIn.href = `https://www.linkedin.com/sharing/share-offsite/?url=${link}`;
}
function whatsappsharing(){
const pagetitle = document.querySelector('.title_single_area h1').innerHTML;
const reportexcerpt = jQuery('.post-inner p').text();
const reporttext = reportexcerpt.substring(0,50);
const link = encodeURI(window.location.href);
const msg = encodeURIComponent(reporttext);
const title = encodeURIComponent(pagetitle);
const whatsapp = document.querySelector('.whatsapp');
whatsapp.href = `https://api.whatsapp.com/send?text=${msg}: ${link}`;
}
function telegramsharing(){
const pagetitle = document.querySelector('.title_single_area h1').innerHTML;
const reportexcerpt = jQuery('.post-inner p').text();
const reporttext = reportexcerpt.substring(0,50);
const link = encodeURI(window.location.href);
const msg = encodeURIComponent(reporttext);
const title = encodeURIComponent(pagetitle);
const telegram = document.querySelector('.telegram');
telegram.href = `https://telegram.me/share/url?url=${link}&text=${msg}`;
}`
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment