Help

How to Allow Users to Rate the Articles on Your WordPress Site Using Klix

The Dynamic polls feature of Klix is designed to allow a single widget embed code, to power multiple polls by segmenting results depending on variables supplied by your website.

This makes it simple to generate site-wide polling questions such as 'How would you rate this article?'.

The following is a step-by-step guide on how to use Klix to setup a dynamic poll and use it to get ratings on your article content.

Warning

Dynamic polls are a paid feature and will not work on free accounts

#Step 1 - Setup a Dynamic Poll in your Dashboard

Setting up a dynamic poll involves, firstly creating a poll widget in your dashboard. Once that is done edit the poll widget, and add a new question or edit an existing question:

Change the question properties as follows:

  • Ensure the Dynamic toggle is ON
  • Question: How do you rate this article?
  • Left Answer: Hate It
  • Right Answer: Love It!
  • Prompts: Add prompts as you see fit!

#Step 2 - Add a Shortcode to WordPress To Generate Your Dynamic Embed Code

In order to generate a custom Klix embed code that contains your article title we need to create a WordPress shortcode.

You may already have the ability to generate shortcodes using your theme, or an existing plugin. Or you may prefer to directly edit your themes functions.php file in the WordPress theme editor.

If you are unsure on how to add shortcodes, there are many help guides that already exist that detail exactly how to create them:

There are also a bunch of plugins in the WordPress plugin store that allow you to create php shortcodes such as WPCode, however not all of these are free.

Choose your shortcode solution, and then, all you need to do is add the following php to create your shortcode.

function klix_embed1() {
	$embed_id = '[[embed_id]]'; /* replace with your embed id */
	$data_question = 'Rate this article!';
	$data_segment = get_the_title();
	
	$embed_code = '<div class="klixEmbed" data-id="%1$s" data-question="%2$s" data-segment="%3$s"></div><script src="https://goklix.local/api/embed/%1$s/embed.js" async></script>';
	$embed_code = sprintf( $embed_code,
	$embed_id,
	esc_html( $data_question ),
	esc_html( $data_segment )
	);
	
	return $embed_code;    
}
add_shortcode('klix_embed1', 'klix_embed1');

Ensure that you replace [[embed_id]] with the id of your embed from your original embed code.

The embed id is the string of numbers and letters between the quotes in the data-id attribute, i.e. In the following data-id="01jaz5k24n8sayds7v32dtczke" the id is 01jaz5k24n8sayds7v32dtczke.

You can then use your shortcode within your WordPress article by just adding the following to the article :

[klix_embed1]

Or by using a WordPress shortcode block in the Gutenberg editor.