↓ Skip to Main Content

TheoryApp

Main Navigation

  • Home
  • Java
Home › Web › Add Social Buttons: Facebook, Google, Twitter, Pinterest

Add Social Buttons: Facebook, Google, Twitter, Pinterest

theoryapp Posted on November 15, 2020 Posted in Web Tagged with facebook like, google plusone, pinterest pinit, social sharing, twitter tweet

There are many services online providing all-in-one widgets for social sharing, such as AddThis, ShareThis, etc. However, it is better to build your own one:

  • You don’t want to show your web traffic to others.
  • Too many sharing buttons are useless.
  • It’s enough to have Facebook Like, Twitter Tweet, Google PlusOne and Pinterest PinIt.
  • It is simple and easy, as we show below.

Facebook Like Button

The following code uses iframe to embed a Facebook Like button. We use the URL “http://theoryapp.com/” in the examples. We need to encode this URL so it can be used in query strings for social sharing URLs. The PHP function urlencode does this dynamically.

$url = "http://theoryapp.com/";
$eurl = urlencode($url);       // http%3A%2F%2Ftheoryapp.com%2F

The result is shown below. For details see the facebook document.

Google PlusOne Button

The following code embeds a Google +1 button. To use it, just replace the URL part with your own one.

The result is shown below. For details see the google document.

Twitter Tweet Button

The following code embeds a Twitter Tweet share button for the current page.

The result is shown below. For details see the twitter document.

Tweet

Pinterest PinIt Button

The following code embeds a Pinterest PinIt button for the current page. Note that the page must have some image to be pinned.

The result is shown below. For details see the pinterest document.

Summary

It seems Facebook Like button requires a “href” parameter for the web page to be liked. For the other buttons, by default, they use the URL for the current page where the button is showing, although you can customize the URL by adding parameters.

The official documents:

  • Facebook Like button
  • Google PlusOne button
  • Twitter Tweet share button
  • Pinterest PinIt button

Comments

comments

Post navigation

Previous Post is ‹ Unix Zip/Unzip Command
Next Post is k-wise Independence and Linear Code ›

Recent Posts

  • Customize Mediawiki To Remove Management Links
  • Install and Run PHP on MacOS
  • Load Apache Access Logs into MySQL
  • How to Stop Processes Run by “launchd” in Mac
  • Use PHP Imagick to Combine Multiple Images into One Image
  • Remove a Substring Based on Begining and Ending Tags in PHP
  • Trim Leading Zeros of Numbers in a String with PHP
  • How to Create a Table using jsPDF
  • How to Choose a Random Element from an Array
  • How to Print a List of Items in Rows and Columns in jsPDF

Categories

  • Algorithm
  • BigData
  • Combinatorics
  • DevTool
  • HowTo
  • Java
  • JavaScript
  • MySQL
  • PHP
  • Probability
  • SQL
  • Theory
  • Uncategorized
  • Web

Tags

abstract class abstract method ArrayList boolean function chernoff bound class CSS derandomization divide and conquer dom endswith expression FIFO fourier analysis generic type geocoding google maps html inheritance interface java java collection JavaScript lifo loop mysql object-oriented parser PHP polymorphism probability programming pseudorandom generator random random walk recursion regular expression rss seo sql startswith store locator string twitter xml

Archives

  • May 2024
  • March 2024
  • February 2024
  • January 2024
  • July 2023
  • May 2023
  • March 2023
  • May 2022
  • February 2022
  • December 2021
  • August 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • February 2020
  • January 2020
  • December 2019

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
© 2025 TheoryApp | Powered by Responsive Theme