Disabling built-in shortcodes

You can use the plugin API in order to remove default shortcodes. Use filter su/data/shortcodes to do that.

Table of contents

  1. Disabling all shortcodes
  2. Disabling specific shortcodes
  3. Disabling all shortcodes except custom ones

Disabling all shortcodes

To remove all shortcodes, you should simply remove all elements from shortcode array.

add_filter( 'su/data/shortcodes', 'remove_su_shortcodes' );

/**
* Filter to modify original shortcodes data
*
* @param array $shortcodes Default shortcodes
* @return array Modified array
*/
function remove_su_shortcodes( $shortcodes ) {

// Remove all shortcodes
$shortcodes = array();

// Return modified data
return $shortcodes;

}

Disabling specific shortcodes

Use the same filter as in the previous example in order to remove specific shortcodes. However, not all elements of the array, but only some elements will be removed. For example:

add_filter( 'su/data/shortcodes', 'remove_su_shortcodes' );

/**
* Filter to modify original shortcodes data
*
* @param array $shortcodes Default shortcodes
* @return array Modified array
*/
function remove_su_shortcodes( $shortcodes ) {

// Remove button shortcode
unset( $shortcodes['button'] );

// Return modified data
return $shortcodes;

}

Disabling all shortcodes except custom ones

The following code will disable all shortcodes except those made with the Shortcode Creator add-on.

add_filter(
	'su/data/shortcodes',
	function( $shortcodes ) {

		return array_filter(
			$shortcodes,
			function( $shortcode ) {
				return isset( $shortcode['group'] ) && 'shortcode-creator' === $shortcode['group'];
			}
		);

	},
	99,
	1
);

The following snippet will also remove all shortcode groups.

The code below requires PHP version 5.5 or higher.

add_filter(
	'su/data/groups',
	function( $groups ) {

		return array_filter(
			$groups,
			function( $group ) {
				return in_array( $group, array( 'all' ) );
			},
			ARRAY_FILTER_USE_KEY
		);

	}
);
Helpful?
🤝 Thank you!