Real Testimonials Shortcode

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

Before starting, here is an overview of the Real Testimonials Plugin and the shortcodes it provides:

Plugin Icon
Real Testimonials

"Real Testimonials is a WordPress plugin that lets you effortlessly showcase your customer testimonials. With its user-friendly interface and customizable features, you can easily boost your credibility and trustworthiness."

★★★★☆ (172) Active Installs: 40000+ Tested with: 6.3.2 PHP Version: false
Included Shortcodes:
  • [sp_testimonial]

Real Testimonials [sp_testimonial] Shortcode

The ‘sp_testimonial’ shortcode is a key part of the Testimonial Free Plugin. It dynamically generates testimonials on your WordPress site. This shortcode takes an ‘id’ as an attribute, which refers to the specific testimonial post. If the post is valid and not in the trash, it retrieves the testimonial’s settings and metadata. It then checks whether the stylesheet for the testimonial is already loaded on the page. If not, it enqueues the required stylesheets. A dynamic style is also loaded based on the testimonial’s settings. Finally, it displays the testimonial on the website and updates the options for the page.

Shortcode: [sp_testimonial]

Parameters

Here is a list of all possible sp_testimonial shortcode parameters and attributes:

  • id – The unique identifier of the testimonial post

Examples and Usage

Basic example – A simple way to display the testimonial by referencing its ID.

[sp_testimonial id=1 /]

For more advanced usage, you can also use the shortcode with multiple parameters. In this case, you can display multiple testimonials by referencing their IDs.

Advanced examples – Displaying multiple testimonials by referencing their IDs.

[sp_testimonial id=1,2,3 /]

Using the shortcode to display a testimonial by referencing its ID. If the testimonial is not found or if it’s in the trash, the shortcode will not render anything.

[sp_testimonial id=4 /]

It’s important to note that the ID referenced in the shortcode must correspond to a valid testimonial post ID in your WordPress database. If the ID does not exist or if the testimonial post is in the trash, the shortcode will not render anything.

PHP Function Code

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

Shortcode line:

add_shortcode( 'sp_testimonial', array( $this, 'shortcode_render' ) );

Shortcode PHP function:

function shortcode_render( $attributes ) {

		shortcode_atts(
			array(
				'id' => '',
			),
			$attributes,
			'sp_testimonial'
		);

		$post_id = esc_attr( intval( $attributes['id'] ) );
		// Check the shortcode status.
		if ( empty( $post_id ) || 'spt_shortcodes' !== get_post_type( $post_id ) || 'trash' === get_post_status( $post_id ) ) {
			return;
		}
		$setting_options    = get_option( 'sp_testimonial_pro_options' );
		$shortcode_data     = get_post_meta( $post_id, 'sp_tpro_shortcode_options', true );
		$main_section_title = get_the_title( $post_id );
		ob_start();
		// Stylesheet loading problem solving here. Shortcode id to push page id option for getting how many shortcode in the page.
		// Get the existing shortcode ids from the current page.
		$get_page_data      = self::get_page_data();
		$found_generator_id = $get_page_data['generator_id'];
		// This shortcode id not in page id option. Enqueue stylesheets in shortcode.
		if ( ! is_array( $found_generator_id ) || ! $found_generator_id || ! in_array( $post_id, $found_generator_id ) ) {
			wp_enqueue_style( 'sp-testimonial-swiper' );
			wp_enqueue_style( 'tfree-font-awesome' );
			wp_enqueue_style( 'tfree-deprecated-style' );
			wp_enqueue_style( 'tfree-style' );
			$dynamic_style = self::load_dynamic_style( $post_id, $shortcode_data );
			// Load dynamic style.
			echo '<style id="sp_testimonial_dynamic_css' . esc_attr( $post_id ) . '">' . $dynamic_style['dynamic_css'] . '</style>';
		}

		// Update options if the existing shortcode id option not found.
		self::testimonial_update_options( $post_id, $get_page_data );

		Helper::sp_testimonial_html_show( $post_id, $setting_options, $shortcode_data, $main_section_title );
		return Helper::minify_output( ob_get_clean() );
	}

Code file location:

testimonial-free/testimonial-free/src/Frontend/Frontend.php

Conclusion

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

Comments

Leave a Reply

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