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.

How can I type out a shortcode in a post so that it doesn't get processed by WordPress or hidden by this plugin?

If you want want a shortcode to appear as-is in a post (for example, you are trying to provide an example of how to use a shortcode), can use the shortcode escaping syntax, which is built into WordPress, by using two opening brackets to start the shortcode, and two closing brackets to close the shortcode:

  • [[some_shortcode]]
  • [[an_example style="yes"]some text[/an_example]]

The shortcodes will appear in your post (but without the double brackets).

How can I prevent certain broken shortcodes from being hidden?

Assuming you want to allow the broken shortcodes 'abc' and 'gallery' to be ignored by this plugin (and therefore not hidden if broken), you can include the following in your theme's functions.php file or in a site-specific plugin:

/**
 * Permit certain shortcodes to appear as broken without being hidden.
 *
 * @param string $display        The text to display in place of the broken shortcode.
 * @param string $shortcode_name The name of the shortcode.
 * @param array  $m              The regex match array for the shortcode.
 * @return string
 */
function allowed_broken_shortcodes( $display, $shortcode_name, $m ) {
    $shortcodes_not_to_hide = array( 'abc', 'gallery' );
    if ( in_array( $shortcode_name, $shortcodes_not_to_hide ) ) {
        $display = $m[0];
    }
    return $display;
}
add_filter( 'hide_broken_shortcode', 'allowed_broken_shortcodes', 10, 3 );

Does this plugin include unit tests?

Yes.

Requires: 2.5 or higher
Compatible up to: 4.7.3
Last Updated: 1 month 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