Spectra – WordPress Gutenberg Blocks Shortcode

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

Before starting, here is an overview of the Spectra – WordPress Gutenberg Blocks Plugin and the shortcodes it provides:

Plugin Icon
Spectra – WordPress Gutenberg Blocks

"Spectra – WordPress Gutenberg Blocks is a dynamic plugin designed to enhance your Gutenberg editor. It provides ultimate add-ons for Gutenberg, offering a richer, more customizable editing experience."

★★★★☆ (980) Active Installs: 500000+ Tested with: 6.3.2 PHP Version: 7.4
Included Shortcodes:
  • [spectra_popup]

Spectra – WordPress Gutenberg Blocks [spectra_popup] Shortcode

The Ultimate Addons for Gutenberg’s ‘spectra_popup’ shortcode is designed to display a specific popup based on the ID provided. On execution, it fetches the popup post using the given ID. It then checks if the popup is set and enabled. If all conditions are met, the shortcode outputs the popup’s content. If any condition fails, it returns nothing.

Shortcode: [spectra_popup]

Parameters

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

  • id – Defines the specific popup post to display

Examples and Usage

Basic example – A simple usage of the shortcode to display a popup by referencing its ID.

[spectra_popup id=3 /]

Advanced examples

Using the shortcode to display a popup by referencing its ID, and also specifying the popup type and whether it is enabled or not. The popup will only be displayed if it is enabled and the specified type is set.

[spectra_popup id=3 spectra-popup-type="lightbox" spectra-popup-enabled="true" /]

Another advanced example could be using the shortcode to display a popup by referencing its ID, but the popup will not be displayed if it is not enabled or the specified type is not set.

[spectra_popup id=3 spectra-popup-type="modal" spectra-popup-enabled="false" /]

Please note that the ‘spectra-popup-type’ and ‘spectra-popup-enabled’ attributes are custom attributes and may not exist in your implementation of the spectra_popup shortcode. They are used here for illustrative purposes only.

PHP Function Code

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

Shortcode line:

add_shortcode( 'spectra_popup', array( $this, 'spectra_popup_shortcode' ) );

Shortcode PHP function:

function spectra_popup_shortcode( $attr ) {
		$attr = shortcode_atts(
			array(
				'id' => 0,
			),
			$attr,
			'spectra_popup'
		);

		if ( empty( $attr['id'] ) ) {
			return;
		}

		$popup = get_post( $attr['id'] );
		if ( empty( $popup ) ) {
			return;
		}
		
		$popup_type = get_post_meta( $attr['id'], 'spectra-popup-type', true );
		if ( 'unset' === $popup_type ) {
			return;
		}

		$popup_enabled = get_post_meta( $attr['id'], 'spectra-popup-enabled', true );
		if ( ! $popup_enabled ) {
			return;
		}

		ob_start();
		echo do_shortcode( $popup->post_content );
		$output = ob_get_clean();

		return is_string( $output ) ? $output : '';
	}

Code file location:

ultimate-addons-for-gutenberg/ultimate-addons-for-gutenberg/blocks-config/popup-builder/class-uagb-popup-builder.php

Conclusion

Now that you’ve learned how to embed the Spectra – WordPress Gutenberg Blocks 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 *