問題描述

在 WordPress 中有一個鈎子,我可以使用它來過濾特定的短代碼的輸出?這樣的東西

add_filter('shortcode_output', 'my_filter_function', 2);

function my_filter_function ( $output, $shortcode ) {
    ....
}

$shortcode[my_schortcode]或更好的代碼,它的屬性分為數組。

最佳解決方案

我知道的 There is no filter 旨在針對您想要的個人短信。

您可以使用 shortcode_atts_{$shortcode}過濾屬性。

您可以通過創建自己的回調並將其註冊到原始的短碼插件來劫持另一個短碼。我認為這是你可能需要做的。

概念證明:

function my_gallery_shortcode($atts) {
  return 'howdy';
}
add_shortcode('gallery','my_gallery_shortcode');

現在嘗試使用畫廊:)

次佳解決方案

WordPress 4.7 推出了一個新的過濾器,do_shortcode_tag,做到這一點。

參考文獻

注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。