PHP can’t read JavaScript variables – that’s because they are simply not available at the point that PHP is run.
So, in this case, you are better staying with pure JavaScript to accomplish what is really a UI challenge – it will also make your code cleaner and better organised.
Here is a basic ( untested ) solution:
<script>
$( function() {
color="red"; // default ##
if ( '7' >= reviewsOverall ){
color="blue";
} elseif ( '7' < reviewsOverall ){
color="pink";
}
$('.rwp-users-score').css('background-color', color );
});
</script>
This script could be added inline on the template or added to a scripts.js file and included using wp_enqueue_script()
– https://developer.wordpress.org/reference/functions/wp_enqueue_script/
Related Posts:
- What is the correct way to use WordPress functions outside WordPress files?
- WP-CLI – Selecting PHP version
- Inject post (from specific category) between posts in Loop
- Hide php Notices in Dashboard
- Place page title in header?
- Shortcode to insert
- Gutenberg Blocks doesn’t render correctly when using do_blocks
- WordPress new user / forgot password emails are broken
- How to get year, month and hour in WordPress?
- Calling a method from functions.php on a click of a button
- Specified file failed upload test. wp_upload_handle
- Want to separate sections of posts. Can you restart loop?
- How to change featured content to a different tag in WordPress Twenty Fourteen?
- Using Echo in ShortCode – Stuck
- How do I create comment-reply-button using element not
- Two posts in same div – WP loop
- Compare two meta key values against each other inside the get_posts array?
- Removing WordPress profile fields from non-admins
- WordPress menu deletes when trying to add a hook
- Issue with foreach on duplicate meta_key’s
- Why am I getting ERR_NAME_NOT_RESOLVED when I add a site to my multisite installation? [closed]
- How to display custom field on homepage
- Show custom field if it exists, and show different elements if it doesn’t
- Making Quote Plugin more efficient
- Different database query in function.php using mysqli
- How to do multiple searches (with logical OR) in WP_Query in hook pre_get_posts?
- Create shortcodes within foreach loop (using array)
- PHP Warning: Attempt to read property “term_id” on bool
- Fatal error: Uncaught Error: Call to undefined function test()
- Cannot access wp-admin/wp-login.php (WordPress backend) anymore, what could be wrong?
- wp_enqueue_scripts leads to error
- Passing UTM Parameters To Modify Page In WordPress
- How can I get the values of my WordPress $wpdb query in Jquery?
- Adding function to Genesis genesis_header [closed]
- How create a Shortcode with hover and complex options
- Echo string and function?
- Adding wrapper elements in the_date() like in the_title()?
- WordPress Environment: Dynamic Page using shortcode – how to change the page name for sharing
- Reason to add a name of the theme like (‘menu-1’ => __( ‘Primary’, ‘twentynineteen’ ),) in PHP?
- Should i use the wordpress Options table or to create database table..?
- Where are the src and srcset sizes coming from?
- wp_remote_post empty $_POST
- How can I spin up a new website for a registered user automatically?
- What is the alternative code to if (isset ($_POST) && !empty ($_POST) to avoid warnings?
- Remove item in Checkout
- How to show every second user different types of banners?
- Woocommerce – get_items() returns empty array
- echo esc_url( get_permalink($post->ID) + complete the ID’s url
- Need help with pagination
- get_comments_number() returns 0
- How to add a rewrite endpoint to unattached media?
- Adding Additional Variables on Menus Page
- Querying for specific tags
- Why the dynamic_sidebar() call is putted into an ul tag?
- Accessing an API with jQuery and AJAX
- Timber right sidebar in WordPress theme
- Build A Custom SQL Query for WordPress Search
- Get main parent category for post (WordPress/Advanced Custom Fields)
- How to run complex query using PHP
- Store ajax data in PHP variable
- comment_post (if comment is approved OR $comment_approved === 1) not working?
- Configure WordPress to Use Responsive Image Rendering
- Creating multiple tables with Plugin
- How to edit post meta data before publishing the post it self wordpress?
- How can i create a function tag in my plugin
- Why the responseText containing those two arrow signs at the beginning
- Call jQuery function from PHP?
- How to Get Linked Elements for a specific ml_source_elementid
- Meta Box clears saved field content
- Woocommerce remove menu item on myaccount dashboard
- Adding action item to admin users table and sending email
- Metabox – Displaying the Value of a Metabox
- Using get_the_excerpt in edit-post
- woocommerce plugin bugs
- Getting most popular posts based on Facebook comments count
- WordPress get_post_meta issue
- Woocommerce Price Text
- Best way to define a database with product codes and back-end support?
- WordPress – custom navigation item classes
- Is there a way to randomize and connect a background and header image?
- Post Thumbnail on Single (if elseif else)
- Display pages from specific page template
- If Elseif Query
- dynamically filter by category via sub-menu
- 3 domains, 1 wordpress install, redirecting and changing domains on live site
- Sidebar doesnt get updated?
- Edit the Publish Widget Options
- How can I print out a single stylesheet or javascript link?
- If the_content’s string length is greater than 0, show post otherwise dont
- WordPress post pagination on custom template not working
- get_option(‘admin_email’) not working in wordpress when using ajax call
- wordpress featured image
- Generating a number based on post ID
- How do I update product shipping using PHP in WooCommerce?
- How can I edit the WooCommerce Mini DropDown Cart to read as follows
- base64_encode conflict with convert_smilies in wordpress
- Disable Typed Parameters for JavaScript in PhpStorm? [closed]
- How to modify default tags in wp_head()
- Can’t insert into a database wordpress
- How to get posts by a certain author in inner loop using outer loop variable or post title WordPress