sandywp / plugins / wp-postratings
WP-PostRatings
Adds an AJAX rating system for your WordPress site's content.
Ready in seconds.
v2.0.2 20,000+ installs WP 6.8+ PHP 8.2+

What you get inside
5 screens-
Ratings -> Settings: the shape, the scale, who may rate, and how a repeat is spotted
-
The Templates tab, holding the markup of the control and of every result
-
Ratings -> Logs, every vote with who cast it, filterable by user and by rating
-
The control in a post with a star under the pointer, and the same rating read-only below
-
The Ratings block in the editor, previewing the control for the post it is pointed at, with the sidebar choosing that post and whether the rating can be cast…
About this plugin
WP-PostRatings adds a rating control to any post, page or custom post type. Visitors pick a value, the vote is posted in the background, and the result appears in its place without a page load.
Features
- Ten rating shapes, drawn with CSS rather than shipped as images, so they stay sharp at any size and cost no HTTP requests — numbers among them, for a scale whose points are read rather than counted.
- A scale, or a two-way up/down control, with the rated and unrated colours as settings.
- Template tags and a shortcode for the highest rated, most rated, lowest rated and highest scoring posts, optionally within a category, a tag or a time range.
- A rating log with sortable columns, filters, bulk delete and Screen Options.
- Google rich snippet markup for the post and its aggregate rating.
- A sidebar widget, and a section on the WP-Stats page when that plugin is installed.
Donations
I spent most of my free time creating, updating, maintaining and supporting these plugins, if you really love my plugins and could spare me a couple of bucks, I will really appreciate it. If not feel free to use it without any obligations.
Usage
The simplest way, and the only one that works in a block theme without editing template files, is the shortcode. Put it in the post or page you want rated:
[ratings]rates the post it appears in.[ratings id="1"]shows the rating for post 1, wherever you put it.[ratings id="1" results="true"]shows post 1’s result without letting anyone vote from there.
To put ratings on every post automatically, a classic theme can call the template tag from single.php, archive.php or index.php, anywhere inside the loop:
<?php the_ratings(); ?>
The settings live at WP-Admin -> Ratings -> Settings, which has a Settings tab and a Templates tab.
Showing A Rating In A Block
A Ratings block is available in the editor, under Widgets. Two settings in the sidebar:
- Post ID — leave it at zero to rate the post the block sits in, which is what an empty
[ratings]does, or give an id to show another post’s rating wherever you put the block. - Show the result only — displays the rating without offering to change it, for putting a post’s score somewhere it should not be voted from. This is what
results="true"does.
It renders on the server, so the preview in the editor is the real rating rather than an approximation, and changing your shape, colours or templates updates every post showing it without re-saving anything. The preview is deliberately not clickable: rating from the editor would record a real vote.
The shortcode still works and is not going anywhere. [ratings], [ratings id="1"] and [ratings id="1" results="true"] behave exactly as they always have, and a post already containing one needs no change. The block calls the same code the shortcode calls, so the two render identically — use whichever suits the post.
WP-CLI
wp postratings list
wp postratings list --limit=50 --format=json
wp postratings get 42
wp postratings delete 42 --yes
wp postratings delete --all --what=logs
A rating lives in two places — the running totals each post displays, and a row per vote in the log. --what chooses which to clear: logs, data or both, and both is the default.
REST API
GET /wp-json/postratings/v1/post/<id>
POST /wp-json/postratings/v1/post/<id>/rate
Reading is public, because a rating is public. Rating takes the same wp_postratings_<id>-nonce the rendered control already carries, passed as a nonce parameter, and is subject to the same eligibility and repeat-rating settings as rating through the page.
Each response carries the rendered markup as well as the numbers, because your templates and your chosen shape decide what a rating looks like.
A refusal answers 403, not 400 — a rating already cast, a rating off the end of the scale, a bad nonce. 400 is kept for a parameter this plugin never had a chance to look at. A post that does not exist answers 404, and so does one you are not allowed to rate — a draft belonging to somebody else answers exactly as a deleted post does, rather than confirming it is there.
These routes are an addition. The admin-ajax.php wp_postratings action is unchanged and still supported.
Questions
- How do I change the colour of the ratings?
Go to
WP-Admin -> Ratings -> Settingsand look under Individual Rating Text and Value. Each step on the scale has its own pair of colour swatches, in the Rated and Not rated columns, which is what the oldstars_crystalandstars_darkimage sets were for.Hovering uses the rated colour. If you would rather tell “about to pick” apart from “already recorded”, set
--wp-postratings-color-hoverin your theme.- How do I change the size, spacing or hover colour?
Anything beyond the two colours is a CSS custom property on
.wp-postratings, so this is all it takes in your theme:.wp-postratings { --wp-postratings-size: 24px; --wp-postratings-gap: 4px; --wp-postratings-color-hover: #f7c56b; }Before 2.0.0 a different colour meant a whole extra folder of images, which is why the plugin shipped
stars,stars_crystalandstars_darkseparately. They are all the same shape now.- How do I use my own rating shape?
Register it with the
wp_postratings_shapesfilter. It then appears on the Ratings Settings screen like any built-in shape, and unlike the old approach of dropping a folder intowp-content/plugins/wp-postratings/images/, it survives an update.add_filter( 'wp_postratings_shapes', function ( $shapes ) { $shapes['diamond'] = array( 'type' => 'scale', 'label' => 'Diamonds', 'path' => 'M12 2l10 10-10 10L2 12z', ); return $shapes; } );The path is SVG path data drawn in a 24×24 box. For an up/down control use
'type' => 'updown'and supply'up'and'down'paths instead of'path'.For a scale whose points are numbers rather than a repeated glyph, use
'type' => 'numeric'and supply no path at all — the position is the glyph:add_filter( 'wp_postratings_shapes', function ( $shapes ) { $shapes['points'] = array( 'type' => 'numeric', 'label' => 'Points', ); return $shapes; } );A numeric shape is still a scale, so it appears under Scale on the settings screen and everything that reads a rating goes on reading it the same way. Only the drawing changes.
- Every visitor can rate over and over, or every rating log entry shows the same IP
This is about the Header That Contains The IP field on the Ratings Settings screen.
Leave it blank unless your site is genuinely behind a reverse proxy or CDN such as Cloudflare. Blank means the plugin uses the address your web server actually saw, which is what you want on a normal host.
If you are behind a proxy, name the exact header your proxy sets, for example
HTTP_CF_CONNECTING_IPfor Cloudflare orHTTP_X_FORWARDED_FORfor most load balancers. Two things are worth knowing:- A visitor can send any header they like. If you name a header your own stack does not set and overwrite, anyone can put whatever they want in it and rate as many times as they please.
X-Forwarded-Foris a list,client, proxy1, proxy2. As of 2.0.0 the plugin reads the first valid address in that list rather than storing the whole string. Before 2.0.0 it stored the whole string, which meant a visitor could append one more address and appear to be somebody new on every request.
Because the stored value has changed shape, rating logs recorded through such a header before 2.0.0 will not match any more, and some visitors may be able to rate one more time. Logs recorded without the field set are unaffected.
- How To Change Schema Type?
<?php add_filter( 'wp_postratings_schema_itemtype', 'wp_postratings_schema_itemtype' ); function wp_postratings_schema_itemtype( $itemtype ) { return 'itemscope itemtype="https://schema.org/Recipe"'; } ?>The default schema type is ‘Article’, if you want to change it to ‘Recipe’, you need to make use of the
wp_postratings_schema_itemtypefilter as shown in the sample code above.- How To Add Your Site Logo For Google Rich Snippets
<?php add_filter( 'wp_postratings_site_logo', 'wp_postratings_site_logo' ); function wp_postratings_site_logo( $url ) { return 'https://example.com/logo.png'; } ?>By default, the plugin will use your site header image URL as your site logo. If you want to change it, you need to make use of the
wp_postratings_site_logofilter as shown in the sample code above.- How To Change The Text Screen Readers Announce?
add_filter( 'wp_postratings_ratings_image_alt', function ( $label ) { return $label; } );This is the description a screen reader reads out for a displayed rating, such as “4 votes, average: 3.70 out of 5”. Since 2.0.0 the ratings are drawn with CSS rather than images, so there is no
altortitleattribute involved; the value becomes thearia-labelon the rating.Returning an empty string removes it, which is what this filter was usually used for. Be aware that it leaves the rating with no accessible name at all, so anyone using a screen reader is told nothing about it. Prefer rewording it over removing it.
- How To Display Comment Author Ratings?
add_filter( 'wp_postratings_display_comment_author_ratings', '__return_true' );By default, the comment author ratings are not displayed. If you want to display the ratings, you need to make use of the
wp_postratings_display_comment_author_ratingsfilter as shown in the sample code above.
sandywp / also on the shelf
Try another plugin
5.0 · 50K+ installs
zipaddr-jp is a collaborative tool that automatically inputs addresses from postal codes.
4.7 · 50K+ installs
Template powered live search for any WordPress theme. Does not require SearchWP, but will utilize it if available.
4.2 · 40K+ installs
Adds an AJAX poll system to your WordPress blog. You can also easily add a poll into your WordPress's blog post/page.
Spin up a real WordPress site in seconds.
Test plugins, build a demo, hand a client a link — then squash it and start again. No local setup, no Docker.