[WordPress] 外掛分享: WP Shortcode Shield

首頁外掛目錄 › WP Shortcode Shield
WordPress 外掛 WP Shortcode Shield 的封面圖片
10+
安裝啟用
★★★★★
5/5 分(1 則評價)
4876 天前
最後更新
問題解決
WordPress 3.4+ v1.1.0 上架:2012-04-24

內容簡介

這個外掛允許您在文章和頁面的內容中引用 WordPress 短碼,而不會被 WordPress 自動擴展短碼。該插件利用了 WordPress 短碼 API 不支援嵌套短碼的特性,使得該外掛的短碼可以包含正在記錄的短碼。

短碼解析器對文章內容進行一次單獨的處理。這意味著如果短碼處理程序的$content參數包含另一個短碼,它將不會被解析。

該外掛支援自結束的[shortcode]和包圍[shortcode]content[/shortcode]形式,支援短碼的短名[wp_scs]和詳細的[wp_shortcode_shield]形式。為了簡潔起見,本文檔剩下的部分將使用[wp_scs]短名。

如果使用短碼自結束的形式,你需要使用code屬性並指定你想要記錄的短碼名稱,但不要使用包圍的[和]字符。這是因為在解析短碼時,WordPress會查找第一個出現的' ] '字符來結束短碼。由於這個原因,像這樣的用法:

[wp_scs code="[another-shortcode-name]"]

…WordPress將使用code屬性中的" ] "字符來嘗試結束短碼名稱,這並不是所期望的。因此,該外掛自動向外輸出添加終止的"[ ]"字符,所以像這樣的用法:

[wp_scs code="another-shortcode-name"]

…將在文章或頁面的內容中顯示 [another-shortcode-name]。

如果使用囊括的形式,可以使用包括或不包括'['和']'字符的短碼文本。如果省略了它們,插件將自動為您添加它們,以使像這樣的用法:

[wp_scs][another-shortcode-name][/wp_scs]

…和

[wp_scs]another-shortcode-name[/wp_scs]

…會顯示相同的結果,即[another-shortcode-name]。

最後,需要注意,不能在同一文章或頁面中混用插件短碼的囊括形式和自結束形式,這不是插件的限制,而是 WordPress 實現短碼 API 的方式…。

解析器不能處理相同短碼的囊括形式和非囊括形式的混用。例如,如果你有:

[myshortcode example='non-enclosing' /] non-enclosed content [myshortcode] enclosed content[/myshortcode]

解析器不會把它視為由文本"non-enclosed content"分隔的兩個短碼,而是把它解析為一個囊括'non-enclosed content [myshortcode] enclosed content'的單個短碼。

外掛標籤

開發者團隊

⬇ 下載最新版 (v1.1.0) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「WP Shortcode Shield」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

This plugin allows you to refer to a WordPress shortcode within the content of posts and pages without that shortcode being automagically expanded by WordPress. The plugin takes advantage of the fact that the WordPress ShortCode API does not support nested shortcodes to allow this plugin’s shortcode to wrap the shortcode being documented.

The shortcode parser uses a single pass on the post content. This means that if
the $content parameter of a shortcode handler contains another shortcode, it won’t
be parsed

The plugin supports both the self closing [shortcode] and enclosing [shortcode]content[/shortcode] forms and supports a short form name of the shortcode, [wp_scs] as well as the more verbose [wp_shortcode_shield] form. For the sake of brevity, the remainder of this documentation will use the [wp_scs] short form name.
If using the self-closing form of the shortcode, you need to supply the name of the shortcode you are documenting using the code attribute but without using the enclosing [ and ] characters. This is because when parsing shortcodes, WordPress looks for the first occurrence of the ‘]’ character to terminate the shortcode. As a result of this, usage such as
[wp_scs code="[another-shortcode-name]"]

… WordPress will use the ‘]’ character inside the code attribute to try and terminate the shortcode name, which is not what is desired. Instead, the plugin automagically adds the terminating ‘[‘ and ‘]’ characters to the plugin’s output, so that usage such as
[wp_scs code="another-shortcode-name"]

… will display [another-shortcode-name] in your post’s of page’s content.
If you are using the enclosing form of the shortcode, you can either supply the shortcode to be documented with or without enclosing ‘[‘ and ‘]’ characters; if they are omitted, the plugin will add them for you, so that usage such as
[wp_scs][another-shortcode-name][/wp_scs]

… and
[wp_scs]another-shortcode-name[/wp_scs]

… will display the same results, namely [another-shortcode-name].
Finally a note of caution, you cannot mix the enclosing and self closing form of the plugin’s shortcode within the same post or page; this is not a limitation of the plugin, but the way in which WordPress implements the ShortCode API …

The parser does not handle mixing of enclosing and non-enclosing forms of the same
shortcode as you would want it to. For example, if you have:
[myshortcode example='non-enclosing' /] non-enclosed content [myshortcode] enclosed content
[/myshortcode]
Instead of being treated as two shortcodes separated by the text ” non-enclosed content “,
the parser treats this as a single shortcode enclosing ” non-enclosed content [myshortcode]
enclosed content”.

延伸相關外掛

文章
Filter
Apply Filters
Mastodon