YOP Poll Shortcodes

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

Before starting, here is an overview of the YOP Poll Plugin and the shortcodes it provides:

Plugin Icon
YOP Poll

"YOP Poll is a dynamic WordPress plugin that allows users to create and manage polls on their site. With YOP Poll, you can engage your audience and gather valuable feedback easily."

★★★★✩ (444) Active Installs: 20000+ Tested with: 6.3.2 PHP Version: false
Included Shortcodes:
  • [yop_poll]
  • [yop_poll_archive]

YOP Poll [yop_poll] Shortcode

The YOP Poll shortcode is a powerful tool that lets you embed polls directly into your WordPress site. This shortcode parses regular shortcodes and generates a poll based on the parameters provided. ‘id’ refers to the poll ID, ‘results’ indicates whether to display results (0 for no, 1 for yes), ‘tracking_id’ is for tracking user activity, and ‘show_results’ determines if poll results are shown.

Shortcode: [yop_poll]

Parameters

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

  • id – Unique identifier of the poll
  • results – Controls if poll results are displayed (0 = no, 1 = yes)
  • tracking_id – Code used for tracking user’s votes
  • show_results – Determines when to show the poll results
  • page_id – Automatically gets the ID of the page where the poll is placed

Examples and Usage

Basic example – Here’s an example of a basic usage of the yop-poll shortcode. This code will display the poll with the ID of 1.

[yop_poll id=1 /]

Advanced examples

Displaying a poll by specifying the ID and controlling the visibility of the results. In this case, the poll with the ID of 2 will be displayed and its results will not be visible (0 indicates that the results are hidden).

[yop_poll id=2 results=0 /]

Using the shortcode to display a poll by ID, with a specific tracking ID and controlling the visibility of results. Here, the poll with the ID of 3 is displayed, a tracking ID of ‘abc123’ is set, and the results are visible (1 indicates that the results are shown).

[yop_poll id=3 tracking_id='abc123' results=1 /]

Controlling the visibility of results without specifying a poll ID. This code will display the results of all polls (1 indicates that the results are shown).

[yop_poll results=1 /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'yop_poll', array( $this, 'parse_regular_shortcode' ) );

Shortcode PHP function:

function parse_regular_shortcode( $atts ) {
		$params = shortcode_atts(
			array(
                'id'      => - 1,
                'results' => 0,
                'tracking_id'   => '',
                'show_results' => '',
            ),
			$atts,
			'yop_poll'
		);
		$params['page_id'] = get_the_ID();
		return $this->generate_poll( $params );
	}

Code file location:

yop-poll/yop-poll/public/public.php

YOP Poll [yop_poll_archive] Shortcode

The ‘yop_poll_archive’ shortcode is a powerful tool in the YOP Poll plugin. It displays an archive of polls based on the specified parameters. The shortcode takes parameters like ‘max’, ‘sort’, ‘sortdir’, and ‘show’. ‘Max’ limits the number of polls displayed, ‘sort’ and ‘sortdir’ determine the order of polls, and ‘show’ controls the visibility.

Shortcode: [yop_poll_archive]

Parameters

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

  • max – Determines the maximum number of polls to display.
  • sort – Specifies the sorting criteria for the polls (e.g., date_added).
  • sortdir – Sets the sorting direction, either ascending (asc) or descending (desc).
  • show – Controls which polls to display, all or specific ones.

Examples and Usage

Basic example – The basic usage of the yop-poll_archive shortcode displays the poll archive with default settings. The default settings display all polls, sorted by the date they were added in ascending order.

[yop_poll_archive /]

Advanced examples

Displaying a limited number of polls – By using the ‘max’ parameter, you can limit the number of polls displayed in the archive. For example, to display only the 5 most recent polls, you would use the following shortcode:

[yop_poll_archive max=5 /]

Sorting polls by title – If you want to display the polls sorted by their title in descending order, you can use the ‘sort’ and ‘sortdir’ parameters. Here is an example:

[yop_poll_archive sort="title" sortdir="desc" /]

Displaying only active polls – The ‘show’ parameter allows you to filter the polls displayed in the archive. To display only active polls, use the following shortcode:

[yop_poll_archive show="active" /]

Please note that these are just examples, and you can combine these parameters in any way that suits your needs.

PHP Function Code

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

Shortcode line:

add_shortcode( 'yop_poll_archive', array( $this, 'parse_archive_shortcode' ) );

Shortcode PHP function:

function parse_archive_shortcode( $atts ) {
		$params = shortcode_atts(
			array(
				'max' => 0,
				'sort' => 'date_added',
				'sortdir' => 'asc',
				'show' => 'all',
			),
			$atts,
			'yop_poll_archive'
		);
		$params['page_id'] = get_the_ID();
		return $this->generate_polls_for_archive( $params );
	}

Code file location:

yop-poll/yop-poll/public/public.php

Conclusion

Now that you’ve learned how to embed the YOP Poll 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 *