WordPress Page Builder Shortcode

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

Before starting, here is an overview of the WordPress Page Builder Plugin and the shortcodes it provides:

Plugin Icon
WordPress Page Builder – Zion Builder

"WordPress Page Builder – Zion Builder is a powerful tool designed to assist you in creating stunning website layouts. This plugin simplifies the process, allowing both beginners and professionals to easily design unique webpages."

★★★★☆ (27) Active Installs: 2000+ Tested with: 6.2.3 PHP Version: 5.6.20
Included Shortcodes:
  • [zionbuilder]

WordPress Page Builder [zionbuilder] Shortcode

The Zionbuilder shortcode is used to render specific content on the website. It checks if the template id is present and if the template is built with Zionbuilder. If not, it returns an error. Upon validation, it registers the elements, gets the content, and enqueues the necessary assets for the post. It then returns the content to be displayed on the website.

Shortcode: [zionbuilder]

Parameters

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

  • id – Unique ID to identify the specific template

Examples and Usage

Basic example – The shortcode below displays a specific template by referencing its ID.

[zionbuilder id=101 /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'zionbuilder', [ $this, 'print_shortcode' ] );

Shortcode PHP function:

function print_shortcode( $attrs, $content = null ) {
		if ( ! isset( $attrs['id'] ) ) {
			return __( 'Template id missing', 'zionbuilder' );
		}

		$post_id            = apply_filters( 'zionbuilder/shortcode/post_id', $attrs['id'] );
		$post_instance = Plugin::$instance->post_manager->get_post_instance( $post_id );

		if ( ! $post_instance ) {
			return __( 'Template not found', 'zionbuilder' );
		}

		if ( ! $post_instance->is_built_with_zion() ) {
			return sprintf(
				/* translators: %s is the whitelabel plugin name */
				__( 'Template was not built with %s', 'zionbuilder' ),
				Whitelabel::get_title()
			);
		}

		// Register the elements
		$post_template_data = $post_instance->get_template_data();
		
		
		Plugin::$instance->renderer->register_area( $post_id, $post_template_data );

		$content = Plugin::$instance->renderer->get_content( $post_id );
		Assets::enqueue_assets_for_post( $post_id );
		Assets::enqueue_scripts_for_elements( $post_template_data );

		return $content;
	}

Code file location:

zionbuilder/zionbuilder/includes/Shortcodes.php

Conclusion

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