[WordPress] 外掛分享: Priority Shortcodes

首頁外掛目錄 › Priority Shortcodes
10+
安裝啟用
☆☆☆☆
1/5 分(1 則評價)
701 天前
最後更新
問題解決
WordPress 2.5.0+ v2.0.2 上架:2014-09-19

內容簡介

你是否曾經因 TinyMCE+wpautop+do_shortcode 而感到煩惱或挫敗,它們會破壞你的簡碼 (shortcode),將 <p> 標籤包裹在 <div> 標籤周圍,留下孤立的 </p>,並造成各種瘋狂混亂?這款外掛程式允許你指定在執行其他操作之前對簡碼進行處理,並生成你所期望的清潔代碼。

Priority Shortcodes 的運作方式是在 the_content 和 widget_text 鉤子上添加一個具有優先順序高於 wpautop 和 do_shortcode 的動作。結果是,這些其他動作會運行你的簡碼最終輸出,而不是嘗試猜測它是否應該包裹在 <p> 標籤中等。

Codex 說明:

wpautop 認識簡碼語法,並會嘗試不在簡碼前後包裹 p 或 br 標籤。這種方式下的簡碼應確保輸出會被包裹在適當的區塊標籤(例如 <p> 或 <div>)中。

但有時簡碼會站在自己的一行上,懇切地希望被包裹在段落標籤中,有時則不希望。比如生成帶有一些類別的 <span> 標籤的簡碼。(是的,你可能會想使用自訂 TinyMCE 樣式,而不是一個簡單的 span 標籤)。

使用方法

當你想要設定具有優先順序的簡碼時,請在起始處使用 '“[!',例如[my-shortcode]成為[!my-shortcode],[my-shortcode]Some content.[/my-shortcode]成為[!my-shortcode]Some content.[/my-shortcode]。

Gutenberg

新的 WordPress 編輯器「Gutenberg」的使用者可能不會在新編輯器中使用 Priority Shortcodes,但該外掛程式仍可在經典編輯器中使用。

外掛標籤

開發者團隊

⬇ 下載最新版 (v2.0.2) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「Priority Shortcodes」→ 直接安裝(推薦)

原文外掛簡介

Intended for use with the Classic Editor plugin.
Ever get annoyed or frustrated by the way TinyMCE+wpautop+do_shortcode wreak havoc on your shortcodes, wrapping

s around

s, leaving orphan

s, and all sorts of craziness? This plugin allows you to specify shortcodes to be processed before those other actions, generating the clean code you expected.
Priority Shortcodes works by adding an action to the_content and widget_text hooks with a higher priority than wpautop and do_shortcode. The result is that those other actions run your shortcode’s final output, rather than trying to guess if it should be wrapped in

tags, etc.
The Codex says:

wpautop recognizes shortcode syntax and will attempt not to wrap p or br tags around shortcodes that stand alone on a line by themselves. Shortcodes intended for use in this manner should ensure that the output is wrapped in an appropriate block tag such as

or

.

But sometimes shortcodes stand on their own on a line, wanting desperately to be wrapped in a paragraph tag, and sometimes they don’t. Like a shortcode that generates a tag with some classes. (Yeah, you might want to use custom TinyMCE styles instead for a simple span.)
Usage
Where you want to process a shortcode with priority, use “[!” at the start. For example: [my-shortcode] becomes [!my-shortcode] and [my-shortcode]Some content.[/my-shortcode] becomes [!my-shortcode]Some content.[/my-shortcode].
Gutenberg
Users of the new WordPress editor, “Gutenberg”, will probably not use Priority Shortcodes within the new editor, but the plugin continues to work in the Classic Editor.

延伸相關外掛

文章
Filter
Apply Filters
Mastodon