Greenshift Animation And Page Builder Blocks Shortcode

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

Before starting, here is an overview of the Greenshift Animation And Page Builder Blocks Plugin and the shortcodes it provides:

Plugin Icon
Greenshift – animation and page builder blocks

"Greenshift – Animation and Page Builder Blocks is a dynamic WordPress plugin. It enhances your site by offering animated elements and an intuitive page builder, simplifying design tasks."

★★★★☆ (47) Active Installs: 20000+ Tested with: 6.4 PHP Version: 7.0
Included Shortcodes:
  • [wp_reusable_render]

Greenshift Animation And Page Builder Blocks [wp_reusable_render] Shortcode

The Greenshift Animation and Page Builder Blocks shortcode, ‘wp_reusable_render’, is designed to render reusable WordPress blocks. This shortcode extracts attributes such as ‘id’, ‘ajax’, ‘height’, and ‘inlinestyle’. It verifies the ‘id’ and retrieves the page if it is not numeric. If ‘ajax’ is not empty, it enqueues styles and scripts, and generates a div with a unique class. It retrieves the post based on the ‘id’, and if it contains blocks, it parses the blocks and gets inline styles. If ‘height’ is specified, it wraps the content in a div with a minimum height. If ‘ajax’ is empty, it retrieves the post, does the blocks and shortcode, removes unnecessary spaces and line breaks, and appends the style.

Shortcode: [wp_reusable_render]

Parameters

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

  • id – Identifier for the specific reusable block or post
  • ajax – Determines if the block should be loaded asynchronously
  • height – Defines the minimum height of the block
  • inlinestyle – Indicates if inline styles should be applied to the block

Examples and Usage

Basic example – The shortcode displays a reusable block using its ID.

[wp_reusable_render id="123" /]

Advanced examples

Using the shortcode to display a reusable block with a minimum height. The ‘height’ attribute sets a minimum height for the block.

[wp_reusable_render id="123" height="500px" /]

Using the shortcode to load a reusable block via AJAX. The ‘ajax’ attribute set to ‘true’ enables AJAX loading for the block.

[wp_reusable_render id="123" ajax="true" /]

Using the shortcode to display a reusable block with inline styles. The ‘inlinestyle’ attribute set to ‘true’ enables inline styles for the block.

[wp_reusable_render id="123" inlinestyle="true" /]

Using the shortcode to display a reusable block with a combination of attributes. In this example, the block is loaded via AJAX, has a minimum height of 500px, and includes inline styles.

[wp_reusable_render id="123" ajax="true" height="500px" inlinestyle="true" /]

PHP Function Code

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

Shortcode line:

add_shortcode('wp_reusable_render', array($this, 'gspb_template_shortcode_function'));

Shortcode PHP function:

function gspb_template_shortcode_function($atts)
		{
			extract(shortcode_atts(
				array(
					'id' => '',
					'ajax' => '',
					'height' => '',
					'inlinestyle' => ''
				),
				$atts
			));
			if (!isset($id) || empty($id)) {
				return '';
			}
			if (!is_numeric($id)) {
				$postget = get_page_by_path($id, OBJECT, array('wp_block'));
				if (is_object($postget)) {
					$id = $postget->ID;
				} else {
					return;
				}
			}
			if (!empty($ajax)) {
				wp_enqueue_style('wp-block-library');
				wp_enqueue_style('gspreloadercss');
				wp_enqueue_script('gselajaxloader');
				$scriptvars = array(
					'reusablenonce' => wp_create_nonce('gsreusable'),
					'ajax_url' => admin_url('admin-ajax.php', 'relative'),
				);
				wp_localize_script('gselajaxloader', 'gsreusablevars', $scriptvars);
				$content = '<div class="gs-ajax-load-block gs-ajax-load-block-' . (int)$id . '"></div>';

				$content_post = get_post($id);
				if (!is_object($content_post)) return false;
				$contentpost = $content_post->post_content;
				$style = '';
				if (has_blocks($contentpost)) {
					$blocks = parse_blocks($contentpost);
					$style .= '<style scoped>';
					$style .= gspb_get_inline_styles_blocks($blocks);
					$style .= '</style>';
				}
				if (!empty($height)) {
					$content = '<div style="min-height:' . esc_attr($height) . '">' . $content . $style . '</div>';
				} else {
					$content = '<div>' . $content . $style . '</div>';
				}
			} else {
				$content_post = get_post($id);
				if (!is_object($content_post)) return false;
				$content = $content_post->post_content;
				$style = '';
				if ($inlinestyle) {
					if (has_blocks($content)) {
						$blocks = parse_blocks($content);
						$style .= '<style scoped>';
						$style .= gspb_get_inline_styles_blocks($blocks);
						$style .= '</style>';
					}
				}
				$content = do_blocks($content);
				$content = do_shortcode($content);
				$content = preg_replace('%<p>&nbsp;\s*</p>%', '', $content);
				$content = preg_replace('/^(?:<br\s*\/?>\s*)+/', '', $content);
				$content = $content . $style;
			}
			return $content;
		}

Code file location:

greenshift-animation-and-page-builder-blocks/greenshift-animation-and-page-builder-blocks/settings.php

Conclusion

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