WP Review Shortcodes

Below, you’ll find a detailed guide on how to add the Wp Review 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 Wp Review Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Wp Review Plugin and the shortcodes it provides:

Plugin Icon
WordPress Review Plugin: The Ultimate Solution for Building a Review Website

"WordPress Review Plugin: The Ultimate Solution for Building a Review Website is a top-notch tool for creating dynamic, interactive review websites. This plugin simplifies the process, making it easy for everyone to generate engaging review content."

★★★☆✩ (177) Active Installs: 30000+ Tested with: 5.9.8 PHP Version: 7.2
Included Shortcodes:
  • [wp-review]
  • [wp-review-total]
  • [wp-review-visitor-rating]

Wp Review [wp-review] Shortcode

The WP-Review shortcode is a powerful tool for displaying review data on your website. It uses the ‘wp-review’ identifier and accepts an ‘id’ attribute. When invoked, the shortcode enqueues the ‘wp_review-jquery-appear’ script, ensuring smooth display of review data. The ‘wp_review_get_data’ function retrieves the review data based on the provided id. The output is then returned, ready for display.

Shortcode: [wp-review]

Parameters

Here is a list of all possible wp-review shortcode parameters and attributes:

  • id – A unique identifier for the review data

Examples and Usage

Basic example – A simple implementation of the wp-review shortcode, where only the ‘id’ attribute is specified. This will display the review data for the review with the given ID.

[wp-review id=1 /]

PHP Function Code

In case you have difficulties debugging what causing issues with [wp-review] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'wp-review', 'wp_review_shortcode' );

Shortcode PHP function:

function wp_review_shortcode( $atts ) {
	$atts = shortcode_atts(
		array(
			'id' => null,
		),
		$atts,
		'wp-review'
	);

	// Make sure jquery appear is enqueued.
	wp_enqueue_script( 'wp_review-jquery-appear' );

	$output = wp_review_get_data( $atts['id'] );

	return apply_filters( 'wp_review_shortcode', $output, $atts );
}

Code file location:

wp-review/wp-review/includes/shortcodes.php

Wp Review [wp-review-total] Shortcode

The WP-Review plugin shortcode enables site owners to display a total review score on their website. This shortcode is customizable, allowing for changes in color, context, and class. This shortcode fetches the total review score of a specified product or post. It also allows for the customization of the display, such as the color of the score and the context in which it appears.

Shortcode: [wp-review-total]

Parameters

Here is a list of all possible wp-review-total shortcode parameters and attributes:

  • id – Assigns a unique identifier to the review.
  • class – Defines the CSS class of the review.
  • context – Sets the context in which the review is displayed.

Examples and Usage

Basic example – A simple usage of the wp-review-total shortcode to display the total review score of a specific post by its ID.

[wp-review-total id=45 /]

Advanced examples

Displaying the total review score of a specific post by its ID, but with a custom CSS class for styling purposes.

[wp-review-total id=45 class="custom-review-class" /]

Using the wp-review-total shortcode to display the total review score of a product rating with a specific color scheme.

[wp-review-total id=45 context="product-rating" /]

Combining multiple parameters to display the total review score of a product rating with a specific color scheme and a custom CSS class.

[wp-review-total id=45 class="custom-review-class" context="product-rating" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [wp-review-total] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'wp-review-total', 'wp_review_total_shortcode' );

Shortcode PHP function:

function wp_review_total_shortcode( $atts ) {
	$atts = shortcode_atts(
		array(
			'id'      => null,
			'class'   => 'review-total-only review-total-shortcode',
			'context' => '',
		),
		$atts,
		'wp-review-total'
	);

	$args = array(
		'shortcode' => true,
	);

	if ( 'product-rating' === $atts['context'] ) {
		$args = array(
			'color'          => '#fff',
			'inactive_color' => '#dedcdc',
			'context'        => 'product-rating',
		);
	}

	$output = wp_review_show_total( false, $atts['class'], $atts['id'], $args );

	return apply_filters( 'wp_review_total_shortcode', $output, $atts );
}

Code file location:

wp-review/wp-review/includes/shortcodes.php

Wp Review [wp-review-visitor-rating] Shortcode

The ‘wp-review-visitor-rating’ shortcode is used to display the average user rating for a specific post. It fetches the post’s ID, enqueues necessary styles and scripts, and outputs the rating value and count.

Shortcode: [wp-review-visitor-rating]

Parameters

Here is a list of all possible wp-review-visitor-rating shortcode parameters and attributes:

  • id – unique identifier for the post or page

Examples and Usage

Basic example – Utilizing the shortcode to display visitor ratings for a specific post by referencing its ID.

[wp-review-visitor-rating id=5 /]

Advanced examples

Using the shortcode without specifying the post ID. In this case, the shortcode will automatically fetch the ID of the current post and display the visitor ratings for it.

[wp-review-visitor-rating /]

Using the shortcode to display visitor ratings for multiple posts. This can be achieved by specifying multiple IDs separated by commas. The shortcode will display the visitor ratings for each post in the order they are listed.

[wp-review-visitor-rating id=5,10,15 /]

PHP Function Code

In case you have difficulties debugging what causing issues with [wp-review-visitor-rating] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'wp-review-visitor-rating', 'wp_review_visitor_rating_shortcode' );

Shortcode PHP function:

function wp_review_visitor_rating_shortcode( $atts ) {
	$atts = shortcode_atts(
		array(
			'id' => get_the_ID(),
		),
		$atts,
		'wp-review-visitor-rating'
	);

	wp_enqueue_style( 'wp_review-style' );
	wp_enqueue_script( 'wp_review-jquery-appear' );
	wp_enqueue_script( 'wp_review-js' );

	ob_start();
	$post_reviews = mts_get_post_reviews( $atts['id'] );
	$value        = $post_reviews['rating'];
	$count        = $post_reviews['count'];
	?>
	<div class="user-review-area wp-review-<?php echo esc_attr( $atts['id'] ); ?> review-wrapper">
		<div class="visitor-rating-shortcode">
			<?php echo wp_review_user_rating( $atts['id'] ); ?>
			<div class="user-total-wrapper">
				<span class="user-review-title"><?php esc_html_e( 'User Rating', 'wp-review' ); ?></span>
				<span class="review-total-box">
					<span class="wp-review-user-rating-total"><?php echo esc_html( $value ); ?></span>
					<small>
						<?php
						printf(
							// Translators: reviews count.
							esc_html__( '(%s vote)', 'wp-review' ),
							'<span class="wp-review-user-rating-counter">' . esc_html( $count ) . '</span>'
						);
						?>
					</small>
				</span>
			</div>
		</div>

	</div>
	<?php
	$text = ob_get_clean();
	return apply_filters( 'wp_review_visitor_rating_shortcode', $text, $atts );
}

Code file location:

wp-review/wp-review/includes/shortcodes.php

Conclusion

Now that you’ve learned how to embed the Wp Review 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.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *