Custom Facebook Sharing Button

For anyone having issues in 2020 this is what I set up the other day and it works fine.

Facebook:
Give your Facebook button an ID of facebook-button:
image
Add the follwing code snippet to the body code of the page in question:

<script>
    const facebookButton = document.getElementById('facebook-button');
    facebookButton.setAttribute('target', '_blank');
    facebookButton.setAttribute(
        'href',
        `https://www.facebook.com/sharer/sharer.php?u=${window.location.href}`
    );
</script>

Twitter:
Give your Twitter button an ID of twitter-button:
image
Add the follwing code snippet to the body code of the page in question:

<script>
    const twitterButton = document.getElementById('twitter-button');
    twitterButton.setAttribute('target', '_blank');
    twitterButton.setAttribute(
        'href',
        `https://twitter.com/share?url=${window.location.href}`
    );
</script>

Linkedin:
Give your Linkedin button an ID of linkedin-button:
image
Add the follwing code snippet to the body code of the page in question:

<script>
    const linkedinButton = document.getElementById('linkedin-button');
    linkedinButton.setAttribute('target', '_blank');
    linkedinButton.setAttribute(
        'href',
        `https://www.linkedin.com/shareArticle?mini=true&url=${window.location.href}&title=${document.title}`
    );
</script>

5 Likes