Update on Oct 4, 2016
There are a lot of plugins to add a like/dislike or voting feature to your wordpress site, and in this post I will walk you through how to create your own “Like this” button.
Warning: This tutorial is NOT newbies friendly. If you don’t have basic understanding of PHP, HTML, ajax or wordpress functions, you can jump directly to this section where you can download a zip file of the whole plugin.
First, we create a button letting users can “like it” to our article.
We store the like count value in a custom field named
_pt_likes. If it doesn’t exist or it’s empty, we show
The extra bit of code here is the $nonce in line 12, this is for security consideration to avoid foul play.
(See Codex here)
Now we define the function to handle the action
First of all, we verify the nonce to make sure the action is legit. If it isn’t, we stop moving on and tell the users “No naughty business please”. Otherwise, we update the like count to the database and show an updated like count value.
By now, you should have seen the like this button appearing in the post.
But we want to make it look nice. Below is a sample css styling that you can paste to the
like-it.css file. Since we are using Fonwawesome icon here, make sure to load the fontawesome styles first.
Ok, now our like it button is more beautiful and professional.
DownloadDownload I have put it all in a zip file as a plugin and you can click above download link to get it.
You can also find more information of this plugin on the release page.