Connect with us

Others

Create Superfast Social Sharing Buttons without JavaScript with simple CSS

Published

on

Social Sharing Buttons

We will soon announce our brand new plugin Ofofonobs Sharing.

We can’t imagine a site without Social Sharing button. It’s must and absolutely required. As title mentions  in this tutorial we will go over steps on how to set up Social Sharing buttons on your blog:

  • without using any WordPress Plugins
  • without any JavaScripts
  • without any performance impact

Do you have any of below questions, then you are at right place:

  • How to Implement Social Sharing
  • Simple FontAwesome Social Sharing Buttons Without JavaScript
  • Social Media Sharing Buttons. No JavaScript. No tracking. Super fast.
  • The Simplest way to Offer Sharing Links for Social Media
  • Adding Social Share Buttons to any WordPress Page, No Plugin.
  • Easy social sharing buttons without JavaScript and tracking
  • DIY Social Sharing Links: Add Social Sharing Buttons without Plugin WP

Create Superfast Social Sharing Buttons without JavaScript with simple CSS

Why implement your own Social Sharing Button?

  • Not all but most of social sharing plugins are not optimized for your need
  • They may load social sharing icons individually which increased unnecessary HTTP requests to your server
  • If you are using official social sharing buttons then it loads Java Script for each Sharing button which eventually impacts your page load speed significantly
  • If your page speed is high, your site will rank high in Google Search
  • If your page speed is high, there are more chances users will return to your site more frequently as it’s smooth experience for them

Let’s check what all scripts your site loads for above 5 social sharing plugins. If you add more then add an extra script for each.

There is no point to load above scripts on each and every page on your site.

Now let’s get started: Create Social Sharing Buttons

Step-1

Go to your theme’s function.php file and paste below code. This will add sharing button at the bottom of the post.

function ofofonobs_social_sharing_buttons($content) {
global $post;
if(is_singular() || is_home()){

// Get current page URL
$ofofonobsURL = urlencode(get_permalink());

// Get current page title
$ofofonobsTitle = htmlspecialchars(urlencode(html_entity_decode(get_the_title(), ENT_COMPAT, ‘UTF-8’)), ENT_COMPAT, ‘UTF-8’);
// $ofofonobsTitle = str_replace( ‘ ‘, ‘%20’, get_the_title());

// Get Post Thumbnail for pinterest
$ofofonobsThumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), ‘full’ );

// Construct sharing URL without using any script
$twitterURL = ‘https://twitter.com/intent/tweet?text=’.$ofofonobsTitle.’&url=’.$ofofonobsURL.’&via=ofofonobs’;
$facebookURL = ‘https://www.facebook.com/sharer/sharer.php?u=’.$ofofonobsURL;
$googleURL = ‘https://plus.google.com/share?url=’.$ofofonobsURL;
$bufferURL = ‘https://bufferapp.com/add?url=’.$ofofonobsURL.’&text=’.$ofofonobsTitle;
$linkedInURL = ‘https://www.linkedin.com/shareArticle?mini=true&url=’.$ofofonobsURL.’&title=’.$ofofonobsTitle;

// Based on popular demand added Pinterest too
$pinterestURL = ‘https://pinterest.com/pin/create/button/?url=’.$ofofonobsURL.’&media=’.$ofofonobsThumbnail[0].’&description=’.$ofofonobsTitle;

// Add sharing button at the end of page/page content
$variable .= ‘‘;
$variable .= ‘

‘;
$variable .= ‘Twitter‘;
$variable .= ‘Facebook‘;
$variable .= ‘Google+‘;
$variable .= ‘Buffer‘;
$variable .= ‘LinkedIn‘;
$variable .= ‘Pin It‘;
$variable .= ‘

‘;

return $variable.$content;
}else{
// if not a post/page then don’t include sharing button
return $variable.$content;
}
};
add_filter( ‘the_content’, ‘ofofonobs_social_sharing_buttons’);

We have used the_content WordPress hook. It displays the contents of the current post/page.

 

Step-2

Open style.css file of your WordPress theme and put below code for better styling.

.ofofonobs-link {
padding: 2px 8px 4px 8px !important;
color: white;
font-size: 12px;
border-radius: 2px;
margin-right: 2px;
cursor: pointer;
-moz-background-clip: padding;
-webkit-background-clip: padding-box;
box-shadow: inset 0 -3px 0 rgba(0,0,0,.2);
-moz-box-shadow: inset 0 -3px 0 rgba(0,0,0,.2);
-webkit-box-shadow: inset 0 -3px 0 rgba(0,0,0,.2);
margin-top: 2px;
display: inline-block;
text-decoration: none;
}

.ofofonobs-link:hover,.ofofonobs-link:active {
color: white;
}

.ofofonobs-twitter {
background: #00aced;
}

.ofofonobs-twitter:hover,.ofofonobs-twitter:active {
background: #0084b4;
}

.ofofonobs-facebook {
background: #3B5997;
}

.ofofonobs-facebook:hover,.ofofonobs-facebook:active {
background: #2d4372;
}

.ofofonobs-googleplus {
background: #D64937;
}

.ofofonobs-googleplus:hover,.ofofonobs-googleplus:active {
background: #b53525;
}

.ofofonobs-buffer {
background: #444;
}

.ofofonobs-buffer:hover,.ofofonobs-buffer:active {
background: #222;
}

.ofofonobs-pinterest {
background: #bd081c;
}

.ofofonobs-pinterest:hover,.ofofonobs-pinterest:active {
background: #bd081c;
}

.ofofonobs-linkedin {
background: #0074A1;
}

.ofofonobs-linkedin:hover,.ofofonobs-linkedin:active {
background: #006288;
}

.ofofonobs-social {
margin: 20px 0px 25px 0px;
-webkit-font-smoothing: antialiased;
font-size: 12px;
}

Step-3

Make sure you clear your site cache. I’m using WP Super Cache plugin on my site. If you want to optimize all setting for WP Super Cache then follow the tutorial.

Step-4

Deactivate and Delete other Social Sharing plugin if you have it installed before. That's it.

You should see beautiful sharing buttons on your site. Check out live example at the start of each post on Ofofonobs.

Disclaimer: We sell any type of script/themes/plugins, we also offer web design/developement, graphics design, SEO, Social media followers, Admob self-clicking. visit our contact page to get in touch with us or WhatsApp (+234) 08114313795.

Ikuesan Oluwaseun is the CEO of Ofofonobs and a Full-stack Developer. Ofofonobs.com is a Nigerian digital media and news platform launched in July 2020. Kindly check our contact page to get in touch with me.

Advertisement
Click to comment

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.

Entertainment

Hyundai Veloster N TCR Makes World Debut in Detroit Hyundai Veloster N TCR Makes World Debut in Detroit
Entertainment5 months ago

Hyundai Veloster N TCR Makes World Debut in Detroit

Just before it sets of to conquer the race tracks of the 2019 International Motor Sports Association Michelin Pilot Challenge series,...

Reconditioned 1974 Honda CB750 Looks as If It Came Straight Out of a Museum Reconditioned 1974 Honda CB750 Looks as If It Came Straight Out of a Museum
Entertainment5 months ago

Reconditioned 1974 Honda CB750 Looks as If It Came Straight Out of a Museum

You might find it hard to believe, but this 1974 Honda CB750 was nothing more than a non-running project a few years...

Beautiful Music for Successful Wedding Videos Beautiful Music for Successful Wedding Videos
Entertainment5 months ago

Beautiful Music for Successful Wedding Videos

When it comes to wedding videos, ensuring you have the right music at hand can make all the difference. Any...

Why it’s better to have a child with someone you don’t love – Yvonne Nelson spills Why it’s better to have a child with someone you don’t love – Yvonne Nelson spills
Entertainment6 months ago

Why it’s better to have a child with someone you don’t love – Yvonne Nelson spills

Popular Ghanaian actress, Yvonne Nelson has revealed why it’s better and advisable for people to have children with people they are not...

Wizkid’s Made In Lagos Hits Half A Billion Streams On Apple Music Wizkid’s Made In Lagos Hits Half A Billion Streams On Apple Music
Entertainment6 months ago

Wizkid’s Made In Lagos Hits Half A Billion Streams On Apple Music

Nigerian superstar, Wizkid has recorded another feat with his Made In Lagos Deluxe album version with a milestone of 500M...

Blake Snell Net Worth Blake Snell Net Worth
Entertainment8 months ago

Blake Snell Net Worth

What is Blake Snell’s net worth? Net Worth: $10 Million Age: 28 Born: December 4, 1992 Country of Origin: United...

Beenie Man Net Worth Beenie Man Net Worth
Entertainment8 months ago

Beenie Man Net Worth

What is Beenie Man’s net worth? Net Worth: $4 Million Age: 47 Born: August 22, 1973 Country of Origin: Jamaica...

How to load an already used recharge card How to load an already used recharge card
Entertainment10 months ago

See how to load an already used recharge card (Topsecrets)

Have you ever gotten free Airtime Credit from MTN? If you haven’t, you’re still dulling yourself. This article will teach...

Nigerians on Twitter find humour in Oxlade's leaked s*x tape Nigerians on Twitter find humour in Oxlade's leaked s*x tape
Entertainment10 months ago

Nigerians on Twitter find humour in Oxlade’s leaked s*x tape

Full video of a fast-rising singer identified as Oxlade smashing an unidentified lady breaks the internet, Brand Spur Nigeria reports. In the tape...

Oxlade S*x Tape With Unidentified Lady Breaks Internet Oxlade S*x Tape With Unidentified Lady Breaks Internet
Breaking News10 months ago

Oxlade S*x Tape With Unidentified Lady Breaks Internet

Full video of a fast-rising singer identified as Oxlade smashing an unidentified lady breaks the internet, Brand Spur Nigeria reports. The 24-year-old whose...

ADVERTISEMENT