WordPress.org

Plugin Directory

Hide Broken Shortcodes

Prevent broken shortcodes from appearing in posts and pages.

Filters

The plugin is further customizable via two filters. Typically, these customizations would be put into your active theme's functions.php file, or used by another plugin.

hide_broken_shortcode

The 'hide_broken_shortcode' filter allows you to customize what, if anything, gets displayed when a broken shortcode is encountered. Your hooking function can be sent 3 arguments:

Arguments :

  • $default (string): The default display text (what the plugin would display by default)
  • $shortcode (string): The name of the shortcode
  • The text bookended by opening and closing broken shortcodes, if present

Example:

/**
 * Don't show broken shortcodes or the content they wrap.
 *
 * @param string $default The output the plugin would normally show.
 * @param string $shortcode The name of the shortcode.
 * @param string $content The text between the opening and closing "tags" of the shortcode, if any.
 * @return string
 */
function hbs_handler( $default, $shortcode, $content ) {
    return ''; // Don't show the shortcode or text bookended by the shortcode
}
add_filter( 'hide_broken_shortcode', 'hbs_handler', 10, 3 );

hide_broken_shortcodes_filters

The 'hide_broken_shortcodes_filters' filter allows you to customize what filters to hook to find text with potential broken shortcodes. The three default filters are 'the_content', 'the_excerpt', and 'widget_text'. Your hooking function will only be sent one argument: the array of filters.

Example:

/**
 * Make Hide Broken Shortcodes also filter 'the_title'.
 *
 * @param  array $filters_array The filters the plugin will handle.
 * @return array
 */
function hbs_filter( $filters_array ) {
    $filters_array[] = 'the_title'; // Assuming you've activated shortcode support in post titles
    return $filters_array;
}
add_filter( 'hide_broken_shortcodes_filters', 'hbs_filter' );

Requires: 2.5 or higher
Compatible up to: 4.2.2
Last Updated: 2015-4-2
Active Installs: 600+

Ratings

5 out of 5 stars

Support

Got something to say? Need help?

Compatibility

+
=
Not enough data

0 people say it works.
0 people say it's broken.

100,2,2
100,1,1
100,1,1
100,1,1
100,1,1
100,1,1
0,1,0
100,1,1
100,1,1
100,1,1