問題描述
我正在嘗試刪除一個使用子主題的 elegant-themes 主題的主題操作。當我在父主題 functions.php 中的任何位置刪除 add_action 程式碼之後的操作時,這可以工作。但是,當我從 child theme functions.php 中新增它時,它不起作用。
remove_action ('after_setup_theme', 'et_pb_setup_theme' , 10);
刪除操作與新增操作具有相同的優先順序 10 。應該不行嗎
add_action( 'after_setup_theme', 'et_pb_setup_theme' ); //parent theme add_action
最佳解決方案
正如 @cybmeta 已經指出的那樣,你的清除時間太早了。所以你必須推遲實際刪除,例如:
add_action( 'after_setup_theme', 'wpdev_170663_remove_parent_theme_stuff', 0 );
function wpdev_170663_remove_parent_theme_stuff() {
remove_action( 'after_setup_theme', 'et_pb_setup_theme' );
}
次佳解決方案
子主題的 functions.php 檔案在父主題 functions.php 之前載入,所以當您在子主題中執行 remove_action 時,您嘗試刪除的操作不存在 beacuse,稍後新增。
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。