2013-11-18

There are many WordPress Free and Paid plugins that make sharing WP posts and images over social media channels like Facebook and Twitter very easy.

Now, going one step ahead of this, what if we want go ahead and record/capture these social shares and add some specific functionality like rewarding users for sharing?

This is something that will be good for website SEO also, in the longer run.

Let’s say, we have a WordPress website, with a Pinterest like theme on it. The basic requirement is for us to allow users to share their choice of images posted on this site easily, while capturing/recording these shares.

If the user tweets or shares the picture, the website admin and the user should get some sort of notification that the picture was successfully shared.

Implementing the Basic Concept (WordPress Integration with Third-Party APIs)

First and foremost, to make Social Sharing Easy, we need to implement a URL shortening script like YOURLS. The idea behind using a URL shortening service is that the post looks clean and elegant after sharing and you can still add copy in your Tweet while being in the 140 character range.

There are various other URL shortening service API that could be used for this. (A good list could be found here.) We would only need to check if the other API provides the necessary functions for the social shares to be tracked correctly.



This script can then be invoked automatically to shorten the Post URL before sharing on Twitter and Facebook whenever a user clicks to share.

First, we will have to install YOURLS script on the site and configure it as per the mentioned API documentation.

To Install YOURLS – http://yourls.org/#Install

To Configure YOURLS – http://yourls.org/#Config

We can then place the Twitter (tweet) and Facebook (share) buttons near the image.

(For Example: Bottom Left Corner of the image would be a sweet spot).

Once YOURLS is set-up, we can go ahead for Twitter and Facebook integration.

Integrating Twitter



For Twitter integration, we need to add the optimum functionality where post successful shares, feedback can be provided to our plugin to determine if the picture was shared. This can be done by exploring the widgets.js of Twitter’s API.

In some cases, if the above direct approach doesn’t work on some WordPress installations, then we will have to do some conditional checks to figure out if the user Tweeted the link successfully or not.

This can be done with the following concept -

Before sending the user to Twitter, check last tweet ID of our link and store it in variable A.

Send the user to Twitter to tweet about our link.

When the user comes back to our site, we will check the last tweet ID again and store it in variable B.

If variable A and B equals then it becomes obvious that the user did not tweet the link successfully.

If A doesn’t equal to B then we can conclude that the link was tweeted successfully.

Integrating Facebook



Facebook has recently deprecated the Share button and users are now compelled to use the Like button instead. This Like button basically shares the link/page as a new story on the Facebook user’s timeline.

The other advantage of using a URL shortening service like YOURLS is that your website can add a custom Marketing Message with every share.

We will now have to check if the user clicks on the like button.

This can be done using a simple code as given below.

This code is basically an event handler, which tells the browser to execute the code if the like button is pressed.

You can read more about it here – FB.Event.Subscribe.

Adding a Points System to Reward Users

If you wish to reward the user with some points for sharing the links or pages, then we will require a database connection. Also, user registration will be required to assign points to the corresponding user.

The points can be simply added with a count variable, which will increment when the event of Like or Tweet is successful. This variable can then be used to update the data in the database.

If you don’t wish to reward the user then the database connection is not required. A simple “success” message would suffice.

Based on this approach, using WordPress Development and API Programming we now have the scalability to integrate this plugin with additional Social Networks like LinkedIn.com, Google+  etc.

The post Facebook & Twitter integration with WordPress: How-To Create a Social Rewards System via URL Shortening appeared first on WisdmLabs.

Show more