0
是否有一個函數可以檢索當前前端顯示的WordPress側邊欄?獲取WordPress Sidebars Fom當前前端
是否有一個函數可以檢索當前前端顯示的WordPress側邊欄?獲取WordPress Sidebars Fom當前前端
我張貼可能的工作,這裏的解決方案:Checking If A WordPress Widget Displayed In The Current Front End
dynamic_sidebar不註冊,它一直呼籲建立和側欄。你自己也沒有合適的鉤子。所以我擔心你不得不告訴Wordpress每個模板都顯示了哪些邊欄。
一種方式做,這是創建這樣
function wrap_dynamic_sidebar($sidebar_id)
{
global $sidebars_in_this_template;
$sidebars_in_this_template[] = $sidebar_id;
return dynamic_sidebar($sidebar_id);
}
的包裝功能和無處不在替換這個dynamic_sidebar(但據我所知,這是很可能該解決方案將不會對你可行)。
如果你想顯示所有的側邊欄的列表,你可以使用$ wp_registered_sidebars
global $wp_registered_sidebars;
$sidebar_ids = array_keys($wp_registered_sidebars);
假設我們正在創建的插件和更換'dynamic_sidebar'在所有模板是很難做到的。 – zourbuth
有很多類似的情況;兒童主題等。但是在dynamic_sidebar中缺少過濾器來傳遞側邊欄ID意味着實際上沒有任何完美的解決方案。這並不是我們沒有找到它。它_just不存在_。 –