Logo Pupungbp.com

Need a WordPress expert help?

Add Social Sharing Without Plugin

Last Updated: July 25, 2020 | Reading Time: < 1 minute

Its annoying if you want to use the social sharing button, but the plugin you choose bloated with numerous unused features and ads. The best way is to include your own social sharing feature.

Facebook

It’s a quite popular social media platform, to add this to your theme, facebook use this following URL:

https://www.facebook.com/sharer.php?u=[permalink]

So you can create a link using the above target and add url of the page so the end of the code in WordPress should be like this

<a href="https://www.facebook.com/sharer.php?u=<?php the_permalink(); ?class="ps-share">Share to Facebook</a>

Twitter

For Twitter the url for sharing more or less are the same, but Twitter has abilities to add Text automatically to the share interface:

https://twitter.com/share?url=[url]&text=[text]

So the code in WordPress should be like this:

<a href="//twitter.com/share?url=<?php the_permalink(); ?>&text=<?php echo urldecode( get_the_title() ); ?>" class="ps-share">Share to Twitter</a>

I will update this post later on with more social media sharing code.

Make Them Pop

To pake the sharing window as a popup, instead of opening in current window, use the code below.

<script>
$('.ps-share').click(function (event) {
        window.open($(this).attr("href"), "popupWindow", "width=600,height=400,scrollbars=no");
        event.preventDefault();
    });
</script>

Looking for an affordable WordPress solution?

We offer budget-friendly WordPress website development services to meet your needs. Prices start at $10.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.