How to add like and dislike buttons to WordPress content
WordPress does not include general like and dislike voting for self-hosted content, so you need a plugin or custom code. A manual build uses buttons, AJAX, vote storage and duplicate-vote protection; for most sites, a plugin is the faster and safer route.
- 01Decide how voting should work
- 02Understand the manual route
- 03Install a voting plugin
- 04Place the buttons carefully
- 05Test voting before launch
- 06Take the fast route
What you need
- A self-hosted WordPress site with administrator access
- A clear choice of content types, such as posts, pages, comments or products
- A staging site or recent backup before changing code
Decide how voting should work
Choose where the controls belong: posts, pages, comments, WooCommerce products or custom post types. Decide whether visitors can vote, whether users must be logged in, whether one person can change or remove a vote, and whether you will show separate like and dislike totals.
Also decide whether the buttons should appear automatically or only where you place them. Writing these rules down prevents a common problem: displaying one set of buttons automatically and then adding a second set with a block or shortcode.
Understand the manual route
You can build this without a plugin, but it is a small application rather than a simple button edit. Add the controls with a shortcode or a content/comment filter, load the front-end JavaScript through wp_enqueue_scripts, and send votes to WordPress through admin-ajax.php. Logged-in and logged-out visitors need separate AJAX handling, using the authenticated and unauthenticated WordPress AJAX actions.
The handler must verify a nonce with check_ajax_referer(), validate the post or comment ID, prevent repeat votes, and save votes in a structure that records the voter and the target rather than blindly incrementing a number. Nonces help verify requests but are not authentication or access control.
This route gives you control, but you must maintain the JavaScript, database logic, spam protection, privacy behaviour, accessibility, cache compatibility and migration code. It is usually fine for a developer maintaining a small, bespoke feature, but it is not the quick route for a content site.
Install a voting plugin
For the practical route, open Plugins → Add New Plugin, search for a like and dislike plugin, then install and activate one that supports your required content types. Plugins in this category commonly provide automatic placement, live counts, guest-vote restrictions, comment voting and a block or shortcode for manual placement.
After activation, open the plugin settings and select the content types, button position, labels, icons and voting rules. If the plugin offers a choice between browser, IP or logged-in restrictions, remember that IP limits can treat everyone on the same office or household network as one voter.
Place the buttons carefully
Use automatic placement if every post should have the controls. Use the plugin’s block or shortcode when the buttons belong in a particular section, template, page-builder layout or only on selected content. Shortcode callbacks should return their output rather than print it directly, which avoids output appearing in the wrong place.
Do not use automatic placement and manual placement for the same content unless you have deliberately disabled one of them. If you add buttons to comments, make sure each control is tied to the comment ID, not just the parent post ID, or every comment may share one vote total.
Test voting before launch
Test as an administrator, a logged-in user and a logged-out visitor. Check that a second click removes or changes the vote if that is your chosen rule, that the count updates after a refresh, and that two different posts or comments do not share a total.
Test with your page-cache and JavaScript optimisation settings enabled. Cached HTML can show an old count, while minification or deferred scripts can leave a voting control stuck loading; clear the cache and exclude the voting script if the controls stop responding. Also test keyboard focus, mobile layout, screen-reader labels and whether the buttons appear in archives or excerpts by mistake.
Take the fast route
For the quickest setup, use WP ULike Pro. It provides configurable like and dislike buttons, counts and engagement statistics for posts, comments and WooCommerce products, with placement, styling and shortcode options. Install it, activate it, choose the content types and voting rules, then adjust the button design and position in its settings.
Use the manual route only when you need a voting model that the plugin cannot provide or you are comfortable maintaining custom PHP, JavaScript and vote-storage logic. For a normal blog, store, documentation site or community site, the plugin avoids most of the work that causes duplicate votes, broken counts and cache-related failures.
Let WP ULike Pro do it
Adds customizable likes, dislikes, counts, and engagement stats across posts, comments, and WooCommerce products.
Sources
- developer.wordpress.org /reference/functions/add_shortcode/?utm_source=openai
- developer.wordpress.org /reference/functions/check_ajax_referer/?utm_source=openai
- wordpress.org /plugins/like-dislike-for-wp/?utm_source=openai
Questions
- Can I add like and dislike buttons without a plugin?
- Yes, but custom code must handle the button output, JavaScript, AJAX requests, nonce checks, logged-in and guest voters, duplicate-vote protection and vote storage. You also need to maintain compatibility with caching, themes and WordPress updates. A plugin is usually the better choice unless you need a very specific voting system and can maintain the code.
- Where should WordPress store likes and dislikes?
- Store each vote with the target content ID, vote type and voter identity rather than only increasing a post’s number. Post meta can work for a simple counter, but it does not by itself prevent repeat votes or record who voted. A dedicated vote table or a plugin’s managed storage is more suitable when users can change votes or when you need reliable statistics.
- Can visitors vote without logging in?
- Yes, if the voting system supports guest voting. The usual controls are a browser cookie or local identifier, an IP-based restriction, or a combination of those methods. Browser limits are more friendly to shared networks, while IP limits can block several legitimate people in the same office or household. Neither method completely prevents determined abuse, so moderate suspicious activity when votes matter.
- Why do the buttons show twice or display old counts?
- Buttons usually show twice when automatic placement is enabled and the same control is also inserted with a block or shortcode. Old counts are commonly caused by full-page caching, an unrefreshed object cache or a delayed front-end request. Disable one placement method, clear all caches, and check whether JavaScript optimisation is preventing the voting request from running.
- Can I add voting to WordPress comments and WooCommerce products?
- Yes, but the plugin or custom implementation must support those targets separately. Comment voting needs a unique comment ID for each control, while product voting needs WooCommerce product support or a compatible public post type. Check both features before installation, then test a product, a post, a page and several comments so the totals remain attached to the correct content.