WP Table Builder Shortcode

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

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

Plugin Icon
WP Table Builder – WordPress Table Plugin

"WP Table Builder is an intuitive WordPress plugin that simplifies the process of creating and managing tables on your website, making your content more organized and accessible."

★★★★☆ (578) Active Installs: 60000+ Tested with: 6.3.2 PHP Version: 7.4
Included Shortcodes:
  • [wptb]

WP Table Builder [wptb] Shortcode

The WP Table Builder shortcode is a powerful tool that allows for dynamic table creation. It fetches table data based on the given ID. If the table doesn’t exist, it returns an error message. The shortcode also handles internal shortcodes within the table content. If editing is allowed on the frontend, it provides an edit link. If credits are enabled, it adds a ‘Powered By WP Table Builder’ note.

Shortcode: [wptb]

Parameters

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

  • id – Unique identifier for the table to display
  • internal_shortcodes_stop – Flag to prevent recursive parsing of shortcodes

Examples and Usage

Basic example – A simple shortcode usage to display a table with a specific ID.

[wptb id=1 /]

Advanced examples

Displaying a table with a specific ID and prevent internal shortcodes from being processed.

[wptb id=1 internal_shortcodes_stop=1 /]

Displaying a table and adding a custom class to the table container for custom styling.

[wptb id=1 class="my-custom-class" /]

Displaying a table with a specific ID and adding a custom attribute for further customization.

[wptb id=1 data-custom-attribute="custom value" /]

Please note that these examples are based on the provided shortcode function. Some of the examples may not work if the shortcode function doesn’t support the provided attributes.

PHP Function Code

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

Shortcode line:

add_shortcode( 'wptb', array( $this, 'get_table' ) );

Shortcode PHP function:

function get_table( $args ) {
		if ( ! $this->table_exists( $args['id'] ) ) {
			return '[wptb id="' . $args['id'] . '" not found ]';
		}

		// @deprecated
//		do_action( 'wptb_frontend_enqueue_style' );
//		do_action( 'wptb_frontend_enqueue_script' );
		$html = get_post_meta( $args['id'], '_wptb_content_', true );

		if ( preg_match_all( '|<wptb_shortcode_container_element(.+)</wptb_shortcode_container_element>|isU', $html, $arr ) ) {
			foreach ( $arr[1] as $value ) {
				if ( ! isset( $args['internal_shortcodes_stop'] ) && $value ) {
					$pattern = get_shortcode_regex();

					if ( preg_match_all( '/' . $pattern . '/s', $value, $matches ) ) {

						for ( $i = 0; $i < count( $matches[0] ); $i ++ ) {
							$shortcode = $matches[0][ $i ];
							if ( isset( $matches[2][ $i ] ) && $matches[2][ $i ] == 'wptb' ) {

								$shortcode = str_replace( ']', ' internal_shortcodes_stop="1"]', $matches[0][ $i ] );

								$div_outer_html_new = str_replace( $matches[0][ $i ], $shortcode, $value );

								$html = str_replace( $value, $div_outer_html_new, $html );

								$html = str_replace( $div_outer_html_new, do_shortcode( $div_outer_html_new ), $html );
							} else {
								$html = str_replace( $value, do_shortcode( $value ), $html );
							}
						}
					}
				}
			}
		}

		$post_edit_link   = '';
		$post_give_credit = '';
		$after_table      = '';
		$settings_manager = Init::instance()->settings_manager;

		if ( current_user_can( 'manage_options' ) && $settings_manager->get_option_value( 'allow_edit_link_frontend' ) ) {
			$post_edit_link = '<div class="wptb-frontend-table-edit-link">'
			                  . '<a href="' . admin_url( 'admin.php?page=wptb-builder&table=' . $args['id'] ) . '">' . __( "Edit Table", 'wp-table-builder' ) . '</a></div>';
		}

		if ( $settings_manager->get_option_value( 'give_credits_to_wp_table_builder' ) ) {
			$post_give_credit .= '<div class="wptb-frontend-table-powered-by">'
			                     . '<small><i>Powered By </i></small>'
			                     . '<a href="https://wptablebuilder.com/" target="_blank">' . __( "WP Table Builder", 'wp-table-builder' )
			                     . '</a></div>';
		}

		if ( $post_edit_link != '' || $post_give_credit != '' ) {
			$after_table = '<div class="wptb-frontend-table-after">' . $post_edit_link . $post_give_credit . '</div>';
		}

		$html = sprintf( '<div class="wptb-table-container wptb-table-%1$d"><div class="wptb-table-container-matrix" id="wptb-table-id-%1$d" data-wptb-version="%4$s" data-wptb-pro-status="%5$s">%2$s</div></div>%3$s', esc_attr( $args['id'] ), $html, $after_table, esc_attr( get_plugin_data( NS\PLUGIN__FILE__ )['Version'] ), esc_attr( Addon_Manager::check_pro_status() ? 'true' : 'false' ) );

		$html = apply_filters( 'wp-table-builder/filter/table_html_shortcode', $html );

		return ( $html );
	}

Code file location:

wp-table-builder/wp-table-builder/inc/admin/class-tables.php

Conclusion

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