InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Wordpress customization tutorials

  • Handle pagination in wordpress custom php code
  • How to and why disable wordpress cron
  • How to customize wordpress image alt tag
  • How to display date in wordpress pages
  • How to display wordpress page list with specific custom field value
  • How to display wordpress top level pages
  • How to hide a post from home and RSS feed in wordpress
  • How to include bootstrap javascript and css in wordpress post
  • How to include wordpress pages in archives
  • How to override priority and change frequency in Yoast xml sitemap
  • How to remove xmlrpc from wordpress headers
  • How to setup wordpress custom query params with pretty url format
  • How to show wordpress pages on front page with skip_home custom field
  • How to use google custom search for wordpress site
  • How to write custom php in wordpress
  • No frills social share links for Wordpress sites
  • Using Wordpress custom field for displaying code
  • Wordpress - add content filter after shortcode execution
  • Wordpress - customize category and tag links
  • Wordpress - customize facebook plugin opengraph meta tags
  • Wordpress - customize posts per page for tag, category and date archive pages
  • Wordpress - exclude specific posts from archive pages
  • Wordpress - get posts/pages with missing meta key
  • Wordpress - how to add filter to description meta tag
  • Wordpress - how to create custom tag cloud
  • Wordpress - how to exclude specific tag posts from a tag archive page
  • Wordpress - write custom php log to separate file
  • Wordpress how to check if a post is being viewed by admin
 
  • Home
  • > Tutorials
  • > Wordpress
  • > Wordpress customization

No frills social share links for WordPress sites

By admin | Last updated on Mar 20, 2016

There are many plugins available for WordPress which lets visitors share the post or current page on various social networking sites like Google Plus, Facebook, Twitter, Linkedin, Reddit, Digg, Stubleupon, etc.

I tried few popular ones and realized that these plugins pulls lots of javascript and css from the plugin and often from these social networking sites. Some sites use  lazy loading approach. Still I could not find a simple plugin with no javascript, css. I wanted the plugin to insert the links and let me take care of css style. Since these links appear on every post, I’m somewhat obsessed with page performance due to addition of these links.

I finally wrote a simple wordpress plugin for no frills social shareing of links.
Here is the main php source code containing the url parameters needed for sharing at various social sites. The code is also available on github. You many need to customize it little bit as I have used image paths from location /img/

function nfssl_the_content_filter ($content) {
  $posturl = urlencode(get_permalink());
  $posttitle = urlencode(html_entity_decode(get_the_title(), ENT_COMPAT, 'UTF-8'));
  $share_html = "<div class='nfssl'>Share: ";

  // G+
  $link = "https://plus.google.com/share?url=$posturl";
  $title = "share on Google+";
  $img = "/img/Google_plus_icon-18.png";
  $share_html .= " <a title='$title' href='$link' target='_blank'><img src='$img' alt='$title' /></a>";

  // fb
  $link = "http://www.facebook.com/share.php?u=$posturl";
  $title = "share on facebook";
  $img = "/img/F_icon-18.png";
  $share_html .= " <a title='$title' href='$link' target='_blank'><img src='$img' alt='$title' /></a>";

  // linkedin
  $link = "http://www.linkedin.com/shareArticle?mini=true&url=$posturl" . "&title=$posttitle";
  $title = "share on linkedin";
  $img = "/img/Linkedin_icon-18.png";
  $share_html .= " <a title='$title' href='$link' target='_blank'><img src='$img' alt='$title' /></a>";

  // twitter
  $link = "https://twitter.com/intent/tweet?url=$posturl" .  "&text=$posttitle";
  $title = "tweet this";
  $img = "/img/Twitter-18.png";
  $share_html .= " <a title='$title' href='$link' target='_blank'><img src='$img' alt='$title' /></a>";

  // reddit
  $link = "http://www.reddit.com/submit?url=$posturl" . "&title=$posttitle";
  $title = "submit to reddit";
  $img = "/img/Reddit-18.png";
  $share_html .= " <a title='$title' href='$link' target='_blank'><img src='$img' alt='$title' /></a>";

  // stumbleupon
  $link = "http://www.stumbleupon.com/submit?url=$posturl";
  $title = "share on stumbleupon";
  $img = "/img/Stumbleupon-18.png";
  $share_html .= " <a title='$title' href='$link' target='_blank'><img src='$img' alt='$title' /></a>";

  //digg
  $link = "http://digg.com/submit?url=$posturl" . "&title=$posttitle";
  $title = "share on digg";
  $img = "/img/Digg_Shiny_Icon-18.png";
  $share_html .= " <a title='$title' href='$link'><img src='$img' alt='$title' target='_blank' /></a>";

  $share_html .= "</div>\n";
  $content .= $share_html;
  return $content;
}
add_filter( 'the_content', 'nfssl_the_content_filter');

You also need to get the icon images. The icon images are usually available on the respective social sharing/bookmarking site. You can also take the SVG icon images available in public domain and generate required size png icons or other format icons. I prefer the approach of  loading of images from blog domain itself browser does not need to do an additional DNS lookup in that case.

You can use following SVG icons to generate png or other format icon images.

  1. https://commons.wikimedia.org/wiki/File:F_icon.svg
  2. https://commons.wikimedia.org/wiki/File:Google_plus.svg
  3. http://commons.wikimedia.org/wiki/File:Linkedin_icon.svg
  4. https://commons.wikimedia.org/wiki/File:Twitter.svg
  5. http://en.wikipedia.org/wiki/File:Reddit_logo.svg
  6. http://commons.wikimedia.org/wiki/File:Stumbleupon.svg
  7. https://commons.wikimedia.org/wiki/File:Digg.svg
  8. http://commons.wikimedia.org/wiki/File:Diigo.svg

Suggested posts:

  1. How to enable youtube monetization and link to adsense account
  2. Run Internet Explorer (IE) on Mac using VirtualBox and ievms script
  3. Mac brew (homebrew) – quick start guide
  4. Svn log of all files in a directory
  5. How to write custom css in wordpress
  6. Ssh automation on Amazon EC2 Ubuntu Linux
  7. CSS pseudo class :focus
  8. How to use Google custom search with lazy loading approach
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Social Media, Tutorials, Wordpress, Wordpress customization
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress