Skip to content

Instantly share code, notes, and snippets.

@diggeddy
Last active March 30, 2024 08:30
Show Gist options
  • Save diggeddy/ef3dc0315a73c0caad839c5348b89aa6 to your computer and use it in GitHub Desktop.
Save diggeddy/ef3dc0315a73c0caad839c5348b89aa6 to your computer and use it in GitHub Desktop.
function make_star_bar( $atts ) {
$value = shortcode_atts( array(
'stars' =>5,
'color' => '#f00'
),$atts);
$prefix = 'star-bar-';
$uniqueClass = uniqid($prefix);
$percentage = 100 * $value['stars'] / 5;
$html = '<span class="'.$uniqueClass.'">&#9733;&#9733;&#9733;&#9733;&#9733;</span>
<style>
.'.$uniqueClass.' {
background: linear-gradient(90deg, '. $value['color'] . ' ' . $percentage .'%, rgba(0,0,0,0) '. $percentage.'%);
color: rgba(0,0,0,.2);
background-clip: text;
-webkit-background-clip: text;
color: rgba(0,0,0,.2);
}
</style>
';
return $html;
}
add_shortcode('star_bar', 'make_star_bar');
@diggeddy
Copy link
Author

diggeddy commented Feb 2, 2023

@buraste very nice :)

@ahreff
Copy link

ahreff commented Mar 6, 2023

hey guys, one question. so i need to use shortcode with star value on every of my post? Because the data input from ACF is not showing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment