SiteOrigin Widgets Bundle Shortcodes

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

Before starting, here is an overview of the SiteOrigin Widgets Bundle Plugin and the shortcodes it provides:

Plugin Icon
SiteOrigin Widgets Bundle

"SiteOrigin Widgets Bundle is a powerful WordPress plugin that enhances your site's functionality. It offers a collection of customizable, user-friendly widgets to create engaging content with ease."

★★★★☆ (129) Active Installs: 600000+ Tested with: 6.3.2 PHP Version: 5.6.20
Included Shortcodes:
  • [siteorigin_widget]
  • [slide_control]

SiteOrigin Widgets Bundle [siteorigin_widget] Shortcode

The SiteOrigin Widget shortcode enables dynamic content rendering within WordPress. It utilizes the ‘siteorigin_widget_shortcode’ function to customize widget display based on specified attributes. This shortcode retrieves the widget class, checks its existence, and parses the shortcode value. It then sets widget arguments and outputs the widget HTML.

Shortcode: [siteorigin_widget]

Parameters

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

  • class – specifies the widget class to be used
  • id – assigns a unique identifier to the widget

Examples and Usage

Basic example – A simple usage of the ‘siteorigin_widget’ shortcode with a defined widget class.

[siteorigin_widget class="WP_Widget_Calendar" /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'siteorigin_widget', 'siteorigin_widget_shortcode' );

Shortcode PHP function:

function siteorigin_widget_shortcode( $attr, $content = '' ) {
	$attr = shortcode_atts( array(
		'class' => false,
		'id' => '',
	), $attr, 'panels_widget' );

	$attr[ 'class' ] = html_entity_decode( $attr[ 'class' ] );

	global $wp_widget_factory;

	if ( ! empty( $attr[ 'class' ] ) && isset( $wp_widget_factory->widgets[ $attr[ 'class' ] ] ) ) {
		$the_widget = $wp_widget_factory->widgets[ $attr[ 'class' ] ];

		// Parse the value of the shortcode
		preg_match( '/value="(.*?)"/', trim( $content ), $matches );

		if ( ! empty( $matches[1] ) ) {
			$data = json_decode( html_entity_decode( $matches[1] ), true );
		}

		$widget_args = ! empty( $data[ 'args' ] ) ? $data[ 'args' ] : array();
		$widget_instance = ! empty( $data[ 'instance' ] ) ? $data[ 'instance' ] : array();

		$widget_args = wp_parse_args( array(
			'before_widget' => '',
			'after_widget' => '',
			'before_title' => '<h3 class="widget-title">',
			'after_title' => '</h3>',
		), $widget_args );

		ob_start();
		$the_widget->widget( $widget_args, $widget_instance );

		return ob_get_clean();
	}
}

Code file location:

so-widgets-bundle/so-widgets-bundle/base/inc/shortcode.php

SiteOrigin Widgets Bundle [slide_control] Shortcode

The ‘slide_control’ shortcode from the so-widgets-bundle plugin allows you to control the navigation of slides. It accepts ‘next’, ‘prev’, ‘first’, ‘last’, or a specific slide number as parameters. The shortcode also supports custom labels for the slide navigation controls. If an invalid value is passed, an error message is displayed.

Shortcode: [slide_control]

Parameters

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

  • slide – Specifies which slide to display, can be a number or ‘next’, ‘prev’, ‘first’, ‘last’.
  • label – Overrides the default label for the slide control link.

Examples and Usage

Basic example – A simple use of the shortcode to navigate to the next slide.

[slide_control slide="next" /]

Advanced example – In this example, the shortcode is used to navigate to a specific slide by its numeric value. Additionally, a custom label is provided for the navigation link.

[slide_control slide="3" label="Go to slide 3" /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'slide_control', array( $this, 'add_shortcode' ) );

Shortcode PHP function:

function add_shortcode( $atts ) {
		ob_start();
		$atts = shortcode_atts( array(
			'slide' => 'next',
			'label' => '',
		), $atts );

		wp_enqueue_script( 'sow-layout-slide-control' );

		if ( is_numeric( $atts['slide'] ) ) {
			$label = sprintf( __( 'Show slide %d', 'so-widgets-bundle' ), $atts['slide'] );
		} elseif (
			$atts['slide'] == 'next' ||
			$atts['slide'] == 'prev' ||
			$atts['slide'] == 'prev' ||
			$atts['slide'] == 'previous' ||
			$atts['slide'] == 'first' ||
			$atts['slide'] == 'last'
		) {
			if ( $atts['slide'] == 'prev' ) {
				$atts['slide'] = 'previous';
			}

			$label = sprintf( __( '%s slide', 'so-widgets-bundle' ), ucfirst( $atts['slide'] ) );
		} else {
			_e( 'Slide control shortcode error: invalid slide value.', 'so-widgets-bundle' );
		}

		if ( isset( $label ) ) {
			// Handle label overriding.
			$label = empty( $atts['label'] ) ? $label : $atts['label'];

			echo '<a class="sow-slide-control" href="#' . esc_attr( $atts['slide'] ) . '" role="button">' . esc_attr( $label ) . '</a>';
		}

		return ob_get_clean();
	}

Code file location:

so-widgets-bundle/so-widgets-bundle/widgets/layout-slider/layout-slider.php

Conclusion

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