WordPress.org

Plugin Directory

Test out the new Plugin Directory and let us know what you think.

Hide Broken Shortcodes

Prevent broken shortcodes from appearing in posts and pages.

Filters

The plugin is further customizable via two filters. Typically, code making use of filters should ideally be put into a mu-plugin or site-specific plugin (which is beyond the scope of this readme to explain).

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 text to display in place of the broken shortcode.
 * @param string $shortcode The name of the shortcode.
 * @param array  $m         The regex match array for the shortcode.
 * @return string
 */
function hbs_handler( $default, $shortcode, $m ) {
    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.7.3
Last Updated: 4 weeks ago
Active Installs: 700+

Ratings

4.6 out of 5 stars

Support

1 of 1 support threads in the last two months have been marked resolved.

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