Languages: English • Reference/wp star rating 日本語 (Add your language)
Outputs a HTML element with the star rating exposed on a 0-5 scale in half star increments (i.e. 1, 1.5, 2 stars). Optionally, if specified, the number of ratings may also be displayed in the title attribute by passing the $number parameter.
By default, only works in admin screens.
<?php wp_star_rating( $args ); ?>
Results in a star rating like this:
<?php $args = array( 'rating' => 3.5, 'type' => 'rating', 'number' => 1234, ); wp_star_rating( $args ); ?>
The above code outputs the following HTML:
<div class="star-rating" title="3.5 rating based on 1,234 ratings"><div class="star star-full"></div><div class="star star-full"></div><div class="star star-full"></div><div class="star star-half"></div><div class="star star-empty"></div></div>
In order to use this function on the front end, your template must include the wp-admin/includes/template.php file and enqueue the appropriate dashicons CSS font information. Example CSS:
@font-face { font-family: "dashicons"; src: url("../fonts/dashicons.eot"); } @font-face { font-family: "dashicons"; src: url(data:application/x-font-woff;charset=utf-8;base64,/* !! Large amount of data removed, see wp-includes/css/dashicons.css for complete data !! */) format("woff"), url("../fonts/dashicons.ttf") format("truetype"), url("../fonts/dashicons.svg#dashicons") format("svg"); font-weight: normal; font-style: normal; } .star-rating .star-full:before { content: "\f155"; } .star-rating .star-half:before { content: "\f459"; } .star-rating .star-empty:before { content: "\f154"; } .star-rating .star { color: #0074A2; display: inline-block; font-family: dashicons; font-size: 20px; font-style: normal; font-weight: 400; height: 20px; line-height: 1; text-align: center; text-decoration: inherit; vertical-align: top; width: 20px; }
Note the font data in the above CSS has been omitted for clarity. This data must be included in working code. Refer to wp-admin/css/dashicons.css
Since: 3.8
wp_star_rating() is located in wp-admin/includes/template.php