Smart WYSIWYG Blocks Of Content Shortcode

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

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

Plugin Icon
Smart WYSIWYG Blocks Of Content

"Smart WYSIWYG Blocks Of Content is a WordPress plugin that enhances your content creation process. It allows you to create, edit, and manage visually appealing content blocks with ease."

★★★★★ (4) Active Installs: 3000+ Tested with: 4.2.36 PHP Version: false
Included Shortcodes:
  • [smartblock]

Smart WYSIWYG Blocks Of Content [smartblock] Shortcode

The Smart Wysiwyg Blocks of Content (SWBOC) shortcode is a powerful tool that fetches and displays specific content blocks. Using the shortcode [smartblock], you can retrieve any ‘smartblock’ post type by its ID. It temporarily removes the ‘prepend_attachment’ filter, applies ‘the_content’ filter to the post content, and then reinstates the ‘prepend_attachment’ filter. This ensures the content is displayed as intended. The shortcode then returns the processed content.

Shortcode: [smartblock]

Parameters

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

  • id – Specifies the unique identifier of the smartblock post

Examples and Usage

Basic example – Displaying a smart block by referencing its ID.

[smartblock id=1 /]

Advanced examples

Using the shortcode to display multiple smart blocks by referencing their IDs. It will load each block in the order they are listed.

[smartblock id="1,2,3" /]

Using the shortcode to display a smart block by referencing its ID within a post or page. This allows you to embed the smart block within your content.

[smartblock id=1 /]

Using the shortcode to display a smart block by referencing its ID within a widget. This allows you to add the smart block to any widgetized area of your website.

[smartblock id=1 /]

Please note that you need to replace the ‘1’ with the actual ID of the smart block you want to display. You can find the ID of a smart block in the ‘Smart Blocks’ section of your WordPress dashboard.

PHP Function Code

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

Shortcode line:

add_shortcode( 'smartblock', array ( $this, 'swboc_shortcode' ) );

Shortcode PHP function:

function swboc_shortcode( $atts ) {
		extract( shortcode_atts( array (
			'id' => '',
		), $atts ) );
	
		$content = "";

		global $post;
		$temp = $post;
	
		if ( $id != "" ) {
			$args = array (
				'post__in'  => array ( $id ),
				'post_type' => 'smartblock',
			);
		
			$swboc_posts = get_posts( $args );
		
			remove_filter( 'the_content', 'prepend_attachment' );

			foreach ( $swboc_posts as $post ) {
				$content .= apply_filters( 'the_content', $post->post_content );
			}

			add_filter( 'the_content', 'prepend_attachment' );
		}

		$post = $temp;
	
		return $content;
	}

Code file location:

smart-wysiwyg-blocks-of-content/smart-wysiwyg-blocks-of-content/includes/class-swboc-front.php

Conclusion

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