Favorites Shortcode

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

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

Plugin Icon
Favorites

"Favorites is a user-friendly WordPress plugin that allows users to create, manage, and display their favorite posts. With its easy-to-use interface, customization is a breeze."

★★★★☆ (124) Active Installs: 10000+ Tested with: 6.1.4 PHP Version: 5.4
Included Shortcodes:
  • [favorite_button]

Favorites [favorite_button] Shortcode

The ‘Favorite Button’ shortcode is a powerful tool in WordPress. It allows you to display a favorite button on your posts. This shortcode takes three optional parameters: post_id, site_id, and group_id. If these parameters are not provided, they default to null. The shortcode then calls the ‘get_favorites_button’ function, which generates and returns the favorite button with the specified parameters.

Shortcode: [favorite_button]

Parameters

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

  • post_id – The unique identifier of the post.
  • site_id – The unique identifier of the site.
  • group_id – The unique identifier of the group.

Examples and Usage

Basic example – A straightforward usage of the shortcode to display the favorite button for a specific post. In this case, the post ID is set to 1.

[favorite_button post_id=1 /]

Advanced examples

Using the shortcode to display the favorite button for a specific post on a specific site. Here, the post ID is set to 1 and the site ID is set to 2.

[favorite_button post_id=1 site_id=2 /]

Adding an additional parameter to group the favorite button. In this instance, the post ID is set to 1, the site ID is set to 2, and the group ID is set to 3.

[favorite_button post_id=1 site_id=2 group_id=3 /]

Using the shortcode without any parameters. This will display the favorite button for the current post on the current site without any grouping.

[favorite_button /]

PHP Function Code

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

Shortcode line:

add_shortcode('favorite_button', [$this, 'renderView']);

Shortcode PHP function:

function renderView($options)
	{
		$this->setOptions($options);
		$this->options['post_id'] = ( $this->options['post_id'] == "" ) ? null : intval($this->options['post_id']);
		$this->options['site_id'] = ( $this->options['site_id'] == "" ) ? null : intval($this->options['site_id']);
		$this->options['group_id'] = ( $this->options['group_id'] == "" ) ? null : intval($this->options['group_id']);
		return get_favorites_button($this->options['post_id'], $this->options['site_id'], $this->options['group_id']);
	}

Code file location:

favorites/favorites/app/API/Shortcodes/ButtonShortcode.php

Conclusion

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