该插件尚未通过WordPress的最新3个主要版本进行测试。 当与较新版本的WordPress一起使用时,可能不再受到维护或支持,并且可能会存在兼容性问题。

Hide Broken Shortcodes

描述

By default in WordPress, if the plugin that provides the functionality to handle any given shortcode is disabled, or if a shortcode is improperly defined in the content (such as with a typo), then the shortcode in question will appear on the site in its entirety, unprocessed by WordPress. At best this reveals unsightly code-like text to visitors and at worst can potentially expose information not intended to be seen by visitors.

This plugin prevents unhandled shortcodes from appearing in the content of a post or page. If the shortcode is of the self-closing variety, then the shortcode tag and its attributes are not displayed and nothing is shown in their place. If the shortcode is of the enclosing variety (an opening and closing tag bookend some text or markup), then the text that is being enclosed will be shown, but the shortcode tag and attributes that surround the text will not be displayed.

See the Filters section for more customization tips.

Links: Plugin Homepage | Plugin Directory Page | GitHub | Author Homepage

Developer Documentation

Developer documentation can be found in DEVELOPER-DOCS.md. That documentation covers the hooks provided by the plugin.

As an overview, these are the hooks provided by the plugin:

  • hide_broken_shortcode : Customizes what, if anything, gets displayed when a broken shortcode is encountered.
  • hide_broken_shortcodes_filters : Customizes what filters to hook to find text with potential broken shortcodes.

安装

  1. Install via the built-in WordPress plugin installer. Or install the plugin code inside the plugins directory for your site (typically /wp-content/plugins/).
  2. Activate the plugin through the ‘Plugins’ admin menu in WordPress
  3. Optionally filter ‘hide_broken_shortcode’ or ‘hide_broken_shortcodes_filters’ if you want to customize the behavior of the plugin

常见问题

Why am I still seeing a broken shortcode even with this plugin activated?

By default, the plugin only tries to hide broken shortcodes appearing in post/page content, post/page excerpts, and widgets. It does not hide broken shortcodes that may appear in post/page titles, custom fields, menus, comments, etc.

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.

评价

2018 年 12 月 25 日
This plugin does what it says. Really a great plugin. Thank you developer.
2018 年 3 月 3 日
I installed the plugin but shortcode is still appearing The shortcode is a qtranslate language string documentation can be improved and maybe you can add troubleshooting section in the documentation or the reason why it might not work
2017 年 6 月 22 日
Not flashy. Does one thing and does it right. If shortcode isn’t working, readers can’t see it.
阅读所有10条评价

贡献者及开发者

「Hide Broken Shortcodes」是开源软件。 以下人员对此插件做出了贡献。

贡献者

「Hide Broken Shortcodes」插件已被翻译至 2 种本地化语言。 感谢所有译者为本插件所做的贡献。

帮助将「Hide Broken Shortcodes」翻译成简体中文。

对开发感兴趣吗?

您可以浏览代码,查看SVN仓库,或通过RSS订阅开发日志

更新日志

1.9.4 (2021-10-09)

  • New: Add DEVELOPER-DOCS.md and move hooks documentation into it
  • Change: Note compatibility through WP 5.8+
  • Change: Tweak installation instruction
  • Change: Tweak TODO entry
  • Unit tests:
    • Change: Restructure unit test directories
      • Change: Move phpunit/ into tests/
      • Change: Move phpunit/bin into tests/
    • Change: Remove ‘test-‘ prefix from unit test file
    • Change: In bootstrap, store path to plugin file constant
    • Change: In bootstrap, add backcompat for PHPUnit pre-v6.0

1.9.3 (2021-04-18)

  • Change: Note compatibility through WP 5.7+
  • Change: Update copyright date (2021)

1.9.2 (2020-09-06)

  • Change: Restructure unit test file structure
    • New: Create new subdirectory phpunit/ to house all files related to unit testing
    • Change: Move bin/ to phpunit/bin/
    • Change: Move tests/bootstrap.php to phpunit/
    • Change: Move tests/ to phpunit/tests/
    • Change: Rename phpunit.xml to phpunit.xml.dist per best practices
  • Change: Note compatibility through WP 5.5+

Full changelog is available in CHANGELOG.md.