Last active
March 30, 2024 08:30
-
-
Save diggeddy/ef3dc0315a73c0caad839c5348b89aa6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.'">★★★★★</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'); |
@Sparkledump the code is PHP.
If you're using a Child Theme, then add it to the Child theme functions.php
If you're not, then use the Code Snippets plugin to add the code to a new snippet
@buraste very nice :)
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
Hi Gentlemen. I came looking for this and I found it! Question--where do I add this code? I know how to reference the shortcode on my post. Do I create an element with the code? And the element would be a shortcode?