Since version: v1.8.0
Filter acf_tablefield/shortcode/enabled
This filter decides whether the shortcode [tablefieldpro] outputs a table. The default is the setting Enable the shortcode [tablefieldpro] (ACF → Table Field Pro, tab Features), which is off for new installs since 1.8.0, see Enable or disable the shortcode. The filter runs on every shortcode, so it can decide per field or post. When it returns false, the shortcode outputs an empty string.
Parameters
add_filter( 'acf_tablefield/shortcode/enabled', '__return_true' );
-
$enabledtrueoutputs the table,falseoutputs an empty string.- Defaults: The setting Enable the shortcode [tablefieldpro], off for new installs.
-
$attsThe attributes of the shortcode:
field,subfield,post_idandtable_class. Attributes that are not given arefalse.
Example: only for some fields
add_filter( 'acf_tablefield/shortcode/enabled', function( $enabled, $atts ) {
if ( in_array( $atts['field'], array( 'price_table', 'opening_hours' ), true ) ) {
return true;
}
return $enabled;
}, 10, 2 );
With the setting off, only the listed field names are allowed.
Example: only tables of the current post
add_filter( 'acf_tablefield/shortcode/enabled', function( $enabled, $atts ) {
if ( false === $atts['post_id'] || (string) get_the_ID() === (string) $atts['post_id'] ) {
return $enabled;
}
return false;
}, 10, 2 );
This blocks tables of other posts, and also post_id="option".