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.
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

Entertainment2 weeks ago

Complete Guide: Hotel Jobs in Canada with Visa Sponsorship

Hotel Jobs in Canada with Visa Sponsorship   Welcome to a world of exciting opportunities in the heart of hospitality!...

Entertainment4 weeks ago

Truck Drivers Jobs In Canada With Visa Sponsorship

Truck Drivers Jobs In Canada With Visa Sponsorship   This is a great opportunity for aspiring truck drivers! Explore the...

Entertainment4 weeks ago

American Visa Lottery Sponsorship Program: What You Need To Know

American Visa Lottery Sponsorship Program: What You Need To Know   Welcome to a comprehensive guide on the American Visa...

Entertainment4 weeks ago

Cleaning Jobs in USA with Visa Sponsorship – APPLY NOW

Cleaning Jobs in USA with Visa Sponsorship – APPLY NOW   Check out cleaning jobs in the USA with visa...

Entertainment4 weeks ago

U.S. Visa Sponsorship Opportunities in 2024/2025 – Apply Now

U.S. Visa Sponsorship Opportunities in 2024/2025 – Apply Now   Explore career opportunities in the U.S. with evolving international talent...

Entertainment4 weeks ago

Fully Funded University of Miami Stamps Scholarship 2024/2025

If you are looking for scholarships, then you should check out an exciting opportunity for aspiring scholars! The University of...

Entertainment4 weeks ago

Mechanic Jobs in the USA with Visa Sponsorship – APPLY NOW

Mechanic Jobs in the USA with Visa Sponsorship – APPLY NOW   Welcome to a world of opportunity for mechanics...

Entertainment4 weeks ago

Graphic Designer Jobs in USA with Visa Sponsorship – APPLY NOW

Explore exciting opportunities in the field of graphic design with visa sponsorship in the USA. Dive into a world of...

Entertainment4 weeks ago

Accounting Jobs in the USA with Visa Sponsorship – APPLY NOW

Welcome to an unparalleled opportunity for individuals aspiring to build a rewarding career in accounting in the United States with...

Entertainment4 weeks ago

Bartender Jobs in the USA with Visa Sponsorship – APPLY NOW

Bartender Jobs in the USA with Visa Sponsorship – APPLY NOW   Welcome to an extraordinary opportunity for those with...