Reusable Content Blocks Shortcode

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

Before starting, here is an overview of the Reusable Content Blocks Plugin and the shortcodes it provides:

Plugin Icon
Reusable Content Blocks

"Reusable Content Blocks is a valuable WordPress plugin that allows you to create, manage, and effortlessly reuse content blocks throughout your website for consistency and time-efficiency."

★★★★☆ (11) Active Installs: 5000+ Tested with: 6.1.4 PHP Version: 5.6
Included Shortcodes:
  • [rcblock]

Reusable Content Blocks [rcblock] Shortcode

The ‘rcblock’ shortcode from the Reusable Content Blocks plugin is designed to fetch and display content from various sources. It supports multiple page builders like Elementor and Beaver Builder. The shortcode uses the ‘rcb_get_content_func’ function, which takes data source and ID attributes. It checks the source, retrieves the content, and handles potential errors like self-referencing or invalid IDs. It also supports published and unpublished content management. The function ends by returning the fetched content, with custom CSS if available. Shortcode: [rcblock]

Shortcode: [rcblock]

Parameters

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

  • data_source – Determines where the data for the block comes from
  • id – Identifier of the post or page from the main database
  • othe_id – Identifier of the post or page from the other database

Examples and Usage

Basic example – The shortcode displays content from a specific post or page by referencing its ID.

[rcblock id=10 /]

Advanced examples

Using the shortcode to display content from a different data source by specifying the data source and ID. In this case, it will load content from another database.

[rcblock data_source=db_other othe_id=15 /]

Using the shortcode to display content from a specific post or page by referencing its ID, but also specifying a different data source as a fallback option. If the content from the specified ID cannot be found, it will try to load content from the other ID.

[rcblock id=20 data_source=db_other othe_id=25 /]

Please note that the ‘id’ and ‘othe_id’ parameters should be replaced with the actual IDs of the posts or pages you wish to display. The ‘data_source’ parameter can be used to specify a different database as the source of the content.

PHP Function Code

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

Shortcode line:

add_shortcode( 'rcblock', 'rcb_get_content_func' );

Shortcode PHP function:

function rcb_get_content_func( $atts ) {

	$rcbval = shortcode_atts( array(
		'data_source' => '',
		'id' => '',
		'othe_id' => '',
	), $atts );
	
	$pagid = ( $rcbval['data_source'] == 'db_other' ) ? $rcbval['othe_id'] : $rcbval['id'];
	$elmntrbuilt = get_post_meta( $pagid, '_elementor_edit_mode', true );

	if( absint($pagid) ) {
	
	//retun if used same page ID 
		if(get_the_ID() == $pagid ) {
			return __('Oops! You are trying to display contnet of this page in this page itself using shortcode?', 'reusablec-block');
		}
		
		//beaver bulider support
		if ( class_exists( 'FLBuilder' ) && FLBuilderModel::is_builder_enabled( $pagid ) ) {

			FLBuilder::enqueue_layout_styles_scripts_by_id( $pagid );
			
			// Print the styles if we are outside of the head tag.
			if ( ! doing_action( 'wp_enqueue_scripts' ) ) {
				wp_print_styles();
			}
			
			FLBuilder::render_content_by_id( $pagid );

		}
		//elementor support
		if (  class_exists( 'Elementor\Plugin') && $elmntrbuilt ) {

			return Elementor\Plugin::$instance->frontend->get_builder_content( $pagid, $with_css = true );
		}
		
		
		else {
			$page_data = get_post( $pagid );

			if ( get_option('rcb_hide_unpub') && $page_data->post_status !== 'publish') {
				return;
			}

			
			$content = apply_filters('the_content', $page_data->post_content);
			
			//get wpbakery css
			if ( class_exists( 'Vc_Base' ) ) {
				$vc = new Vc_Base;
				$vc->addPageCustomCss( $pagid );
				$vc->addShortcodesCustomCss( $pagid );

			}
					
			//get inline custom css from post meta
			$css = rcb_get_css_from_meta($pagid); 
			$content .= $css;
			
			//filter for further modification scenarios
			$content = apply_filters('rcb_content_filter', $content);
			
			return $content;
			}
		
	
	}
	
	else {
		return __('Invlaied ID', 'reusablec-block');
	}
}

Code file location:

reusable-content-blocks/reusable-content-blocks/1.1.2/reusablec-block.php

Conclusion

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