Soliloquy Lite Shortcode

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

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

Plugin Icon
Slider by Soliloquy – Responsive Image Slider for WordPress

"Slider by Soliloquy is an intuitive WordPress plugin designed to create responsive image sliders. Its functionality enhances visual appeal and user engagement on your site."

★★★★☆ (1011) Active Installs: 50000+ Tested with: 6.1.4 PHP Version: 5.6
Included Shortcodes:
  • [soliloquy]

Soliloquy Lite [soliloquy] Shortcode

The Soliloquy Lite shortcode generates a slider on your page. It pulls the slider from the current post if no attributes are passed. It also allows you to specify a slider by its ID or slug. If no data is found using the ID, it tries to fetch it using the slug. The shortcode also supports custom attributes, allowing you to grab data from a custom source. The output of the slider can be customized using various hooks and filters, providing flexibility in design.

Shortcode: [soliloquy]

Parameters

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

  • id – The unique identifier for the slider.
  • slug – The slug of the slider to display.

Examples and Usage

Basic example – Displaying a Soliloquy Slider by referencing the ID of the slider.

[soliloquy id="123" /]

Advanced examples

Displaying a Soliloquy Slider by referencing the slug of the slider. If the slider cannot be found by slug, it will try to load by ID.

[soliloquy slug="my-slider" /]

Displaying a Soliloquy Slider by referencing both ID and slug. The slider will first try to load by ID, but if not found, it will try to load by slug.

[soliloquy id="123" slug="my-slider" /]

Displaying a Soliloquy Slider by referencing a custom attribute. The custom attribute can be used to grab data from a custom source.

[soliloquy custom_attr="my_custom_data" /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'soliloquy', array( $this, 'shortcode' ) );

Shortcode PHP function:

function shortcode( $atts ) {

		global $post;

		// If no attributes have been passed, the slider should be pulled from the current post.
		$slider_id = false;
		if ( empty( $atts ) ) {
			$slider_id = $post->ID;
			$data      = is_preview() ? $this->base->_get_slider( $slider_id ) : $this->base->get_slider( $slider_id );
		} elseif ( isset( $atts['id'] ) ) {
			$slider_id = (int) $atts['id'];
			$data      = is_preview() ? $this->base->_get_slider( $slider_id ) : $this->base->get_slider( $slider_id );
		} elseif ( isset( $atts['slug'] ) ) {
			$slider_id = $atts['slug'];
			$data      = is_preview() ? $this->base->_get_slider_by_slug( $slider_id ) : $this->base->get_slider_by_slug( $slider_id );
		} else {
			// A custom attribute must have been passed. Allow it to be filtered to grab data from a custom source.
			$data = apply_filters( 'soliloquy_custom_slider_data', false, $atts, $post );
		}

		// If there is no data and the attribute used is an ID, try slug as well.
		if ( ! $data && isset( $atts['id'] ) ) {
			$slider_id = $atts['id'];
			$data      = is_preview() ? $this->base->_get_slider_by_slug( $slider_id ) : $this->base->get_slider_by_slug( $slider_id );
		}

		// Allow the data to be filtered before it is stored and used to create the slider output.
		$this->slider_data = apply_filters( 'soliloquy_pre_data', $data, $slider_id );

		// If there is no data to output or the slider is inactive, do nothing.
		if ( ! $this->slider_data || empty( $this->slider_data['slider'] ) || isset( $this->slider_data['status'] ) && 'inactive' === $this->slider_data['status'] && ! is_preview() ) {
			return false;
		}

		// If the data is to be randomized, do it now.
		if ( $this->get_config( 'random', $this->slider_data ) ) {
			$this->slider_data = $this->shuffle( $this->slider_data );
		}

		// Prepare variables.
		$this->data[ $this->slider_data['id'] ] = $this->slider_data;
		$slider                                 = '';
		$i                                      = 1;

		// If this is a feed view, customize the output and return early.
		if ( is_feed() ) {
			return $this->do_feed_output( $this->slider_data );
		}

		// Load scripts and styles.
		wp_enqueue_style( $this->base->plugin_slug . '-style' );
		wp_enqueue_script( $this->base->plugin_slug . '-script' );

		// Load custom slider themes if necessary.
		if ( 'base' !== $this->get_config( 'slider_theme', $this->slider_data ) ) {
			$this->load_slider_theme( $this->get_config( 'slider_theme', $this->slider_data ) );
		}

		// Load slider init code in the footer.
		add_action( 'wp_footer', array( $this, 'slider_init' ), 1000 );

		// Run a hook before the slider output begins but after scripts and inits have been set.
		do_action( 'soliloquy_before_output', $this->slider_data );

		// Apply a filter before starting the slider HTML.
		$slider = apply_filters( 'soliloquy_output_start', $slider, $this->slider_data );

		// Build out the slider HTML.
		$slider        .= '<div aria-live="' . $this->get_config( 'aria_live', $this->slider_data ) . '" id="soliloquy-container-' . sanitize_html_class( $this->slider_data['id'] ) . '" class="' . $this->get_slider_classes( $this->slider_data ) . '" style="max-width:' . $this->get_config( 'slider_width', $data ) . 'px;max-height:' . $this->get_config( 'slider_height', $this->slider_data ) . 'px;' . apply_filters( 'soliloquy_output_container_style', '', $this->slider_data ) . '"' . apply_filters( 'soliloquy_output_container_attr', '', $this->slider_data ) . '>';
			$slider    .= '<ul id="soliloquy-' . sanitize_html_class( $this->slider_data['id'] ) . '" class="soliloquy-slider soliloquy-slides soliloquy-wrap soliloquy-clear">';
				$slider = apply_filters( 'soliloquy_output_before_container', $slider, $this->slider_data );

		foreach ( (array) $this->slider_data['slider'] as $id => $item ) {
			// Skip over images that are pending (ignore if in Preview mode).
			if ( isset( $item['status'] ) && 'pending' === $item['status'] && ! is_preview() ) {
				continue;
			}

			// Allow filtering of individual items.
			$item = apply_filters( 'soliloquy_output_item_data', $item, $id, $this->slider_data, $i );

			$slider      = apply_filters( 'soliloquy_output_before_item', $slider, $id, $item, $this->slider_data, $i );
			$output      = '<li aria-hidden="true" class="' . $this->get_slider_item_classes( $item, $i, $this->slider_data ) . '"' . apply_filters( 'soliloquy_output_item_attr', '', $id, $item, $this->slider_data, $i ) . ' draggable="false" style="list-style:none">';
				$output .= $this->get_slide( $id, $item, $this->slider_data, $i );
			$output     .= '</li>';
			$output      = apply_filters( 'soliloquy_output_single_item', $output, $id, $item, $this->slider_data, $i );
			$slider     .= $output;
			$slider      = apply_filters( 'soliloquy_output_after_item', $slider, $id, $item, $this->slider_data, $i );

			// Increment the iterator.
			$i++;
		}

				$slider = apply_filters( 'soliloquy_output_after_container', $slider, $this->slider_data );
			$slider    .= '</ul>';
			$slider     = apply_filters( 'soliloquy_output_end', $slider, $this->slider_data );
		$slider        .= '</div>';

		// Increment the counter.
		$this->counter++;

		// Add no JS fallback support.
		$no_js   = apply_filters( 'soliloquy_output_no_js', '<noscript><style type="text/css">#soliloquy-container-' . sanitize_html_class( $this->slider_data['id'] ) . '{opacity:1}</style></noscript>', $this->slider_data );
		$slider .= $no_js;

		// Return the slider HTML.
		return apply_filters( 'soliloquy_output', $slider, $this->slider_data );

	}

Code file location:

soliloquy-lite/soliloquy-lite/includes/global/shortcode.php

Conclusion

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