Below, you’ll find a detailed guide on how to add the Yet Another Stars Rating Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Yet Another Stars Rating Plugin shortcodes not to show or not to work correctly.
Before starting, here is an overview of the Yet Another Stars Rating Plugin and the shortcodes it provides:
"YASR – Yet Another Star Rating Plugin for WordPress is a versatile tool that lets users rate your content, enhancing engagement and user experience."
- [yasr_overall_rating]
- [yasr_user_rate_history]
- []
Yet Another Stars Rating [yasr_overall_rating] Shortcode
The ‘yasr_overall_rating’ shortcode is a part of the Yet-Another-Stars-Rating plugin. This shortcode displays the overall rating of a post or page. It checks if the display of overall ratings is enabled in loops. If it’s disabled and the query isn’t singular, the function returns nothing. Otherwise, it returns the overall rating.
Shortcode: [yasr_overall_rating]
Examples and Usage
Basic example – A shortcode that simply calls the overall rating without any additional parameters.
[yasr_overall_rating /]
PHP Function Code
In case you have difficulties debugging what causing issues with [yasr_overall_rating]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('yasr_overall_rating', 'shortcode_overall_rating_callback');
Shortcode PHP function:
function shortcode_overall_rating_callback ($atts, $content=false, $shortcode_tag=false) {
if (YASR_SHOW_OVERALL_IN_LOOP === 'disabled' && !is_singular() && is_main_query()) {
return;
}
return (new YasrOverallRating($atts, $shortcode_tag))->returnShortcode();
}
Code file location:
yet-another-stars-rating/yet-another-stars-rating/includes/shortcodes/yasr-shortcode-functions.php
Yet Another Stars Rating [yasr_user_rate_history] Shortcode
The Yet-Another-Stars-Rating shortcode ‘yasr_user_rate_history’ displays a user’s rating history. It calls the ‘yasr_users_front_widget_callback’ function. The function loads user rating logs and returns the latest ratings through the user widget. This allows users to view their past ratings conveniently.
Shortcode: [yasr_user_rate_history]
Examples and Usage
Basic example – A simple usage of the yasr_user_rate_history shortcode, this will display the user rating history without any additional parameters.
[yasr_user_rate_history]
PHP Function Code
In case you have difficulties debugging what causing issues with [yasr_user_rate_history]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('yasr_user_rate_history', 'yasr_users_front_widget_callback');
Shortcode PHP function:
function yasr_users_front_widget_callback() {
YasrScriptsLoader::loadLogUsersFrontend();
return (new YasrLastRatingsWidget())->userWidget();
}
Code file location:
yet-another-stars-rating/yet-another-stars-rating/includes/shortcodes/yasr-shortcode-functions.php
Yet Another Stars Rating [null] Shortcode
The Yet Another Stars Rating (YASR) shortcode is designed to display posts within a page. It’s activated using the shortcode: [yasr_display_posts]. This function is only executed if it’s a page, ensuring it doesn’t interfere with other post types.
Shortcode: [null]
Examples and Usage
Basic example – Utilizes the ‘yasr_display_posts’ shortcode to display posts on a page. The shortcode does not require any parameters in this basic usage.
[yasr_display_posts /]
PHP Function Code
In case you have difficulties debugging what causing issues with [null]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('yasr_display_posts', 'yasr_display_posts_callback');
Shortcode PHP function:
function yasr_display_posts_callback($atts, $content, $shortcode_tag) {
if(!is_page()) {
return;
}
return (new YasrDisplayPosts($atts, $shortcode_tag))->returnShortcode();
}
Code file location:
yet-another-stars-rating/yet-another-stars-rating/includes/shortcodes/yasr-shortcode-functions.php
Conclusion
Now that you’ve learned how to embed the Yet Another Stars Rating Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply