Below, you’ll find a detailed guide on how to add the WP Testimonials Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the WP Testimonials Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the WP Testimonials Plugin and the shortcodes it provides:
"WP Testimonials is a user-friendly plugin that enables you to effortlessly display and manage customer testimonials on your WordPress site via widgets."
- [testimonial_widgets]
WP Testimonials [testimonial_widgets] Shortcode
The Testimonial Widgets shortcode allows you to display specific testimonials by referencing their widget-id. It retrieves the widget, deserializes its value, and returns a list of reviews. If the widget-id is invalid or missing, it generates an error message. .
Shortcode: [testimonial_widgets]
Parameters
Here is a list of all possible testimonial_widgets shortcode parameters and attributes:
widget-id
– Specifies the unique identifier of the testimonial widget.
Examples and Usage
Basic example – A simple usage of the shortcode to display a specific widget by referencing its ID
[testimonial-widget widget-id=1 /]
Advanced examples
Using the shortcode to display a specific widget by referencing its ID, and handling the case where the widget does not exist. In this case, an error message will be displayed stating that the widget does not exist.
[testimonial-widget widget-id=999 /]
Using the shortcode without providing a widget ID. In this case, an error message will be displayed stating that the shortcode is deficient and the widget ID is empty.
[testimonial-widget /]
PHP Function Code
In case you have difficulties debugging what causing issues with [testimonial_widgets]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode($this->get_shortcode_name(), [$this, 'shortcode_func']);
Shortcode PHP function:
function shortcode_func($atts)
{
$atts = shortcode_atts(
array(
'widget-id' => null
),
$atts
);
if (isset($atts["widget-id"]) && $atts["widget-id"]) {
$widget = $this->get_widget($atts["widget-id"]);
if ($widget)
{
$val = unserialize($widget->value);
return $this->get_noreg_list_reviews($widget->id, true, $val['2'], $val['3']);
}
else
{
return self::get_alertbox(
"error",
" @ <strong>" . TrustindexTestimonialsPlugin::___('%s plugin', [esc_attr($this->plugin_name)]) . "</strong><br /><br />"
. TrustindexTestimonialsPlugin::___('Widget ID %s does not exists!', [$atts["widget-id"]]),
false
);
}
}
else
{
return self::get_alertbox(
"error",
" @ <strong>" . TrustindexTestimonialsPlugin::___('%s plugin', [esc_attr($this->plugin_name)]) . "</strong><br /><br />"
. TrustindexTestimonialsPlugin::___('Your shortcode is deficient: %s ID is empty! Example: ', [esc_attr($this->plugin_name)]) . '<br /><code>[' . $this->get_shortcode_name() . ' widget-id="12"]</code>',
false
);
}
}
Code file location:
testimonial-widgets/testimonial-widgets/testimonials-plugin.class.php
Conclusion
Now that you’ve learned how to embed the WP Testimonials Plugin shortcode, 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