Connect with us
Padiwise Banner

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, VTU Platform and more. visit our contact page to get in touch with us or WhatsApp (+234) 08114313795. data
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

Entertainment5 months ago

John Okafor Mr. Ibu Biography: Net Worth, Family, Movies And More

John Okafor Mr. Ibu Biography & Net Worth ( Fully Updated ) John Okafor is more commonly known as Mr....

Entertainment5 months ago

Brely Evans Biography: Husband, Books, Age, Career

Brely Evans, who was born on December 9, 1972, in Oakland, California, and raised in Milwaukee, Wisconsin, is a multi-talented...

Entertainment5 months ago

Meet Gbadebo Rhodes Vivour, The Labour Party Governorship Candidate In Lagos State 

Gbadebo Rhodes Vivour profile Gbadebo Chinedu Rhodes-Vivour, popularly known as GRV, is a Nigerian architect, activist, and politician born on...

Entertainment5 months ago

Yinka Okeleye Biography: Age, State Of Origin, Education, Wife, Songs, Girlfriend

Adeyinka Okeleye is a talented Gospel singer and worship leader from Ogun State, Nigeria. He currently serves as the Music...

Entertainment5 months ago

Sunmisola Agbebi Biography: Age, Songs, Family, Boyfriend, Net worth, Education

Sunmisola Elizabeth Agbebi is a talented Nigerian gospel singer with a distinct and energetic style. She is 24 years old...

Entertainment5 months ago

Meet Beatrice Itubo, The LP Governorship Candidate In Rivers State

Beatrice Itubo, the Labour Party gubernatorial candidate for the 2023 governorship election in Rivers State was born on Sunday, June...

Entertainment5 months ago

Meet Somachi Chris Asoluka , The New CEO Of Tony Elumelu Foundation

Somachi Chris Asoluka was announced as the new Chief Executive Officer of Tony Elumelu Foundation on January 9, 2023. She...

Entertainment5 months ago

Tasha Cobbs Leonard Christmas Family Photos With Husband And Children

It’s December 26 and everyone especially married people is sharing their beautiful family photos with matching pajamas . Well, famous...

Entertainment5 months ago

10 THINGS YOU SHOULD KNOW ABOUT DEBORAH PAUL ENENCHE

Deborah Paul Enenche was born on 28 of March 1995 2. She is a Nigerian top-rated gospel singer and first...

Entertainment5 months ago

Lillian Mutambo Biography: Age, Investment , Marriage And More

Lillian Mutambo is a 39 year -old Zambian social worker and youtuber based in the United Kingdom. Music Career Lily...