問題描述
我正在嘗試刪除一個使用子主題的 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 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。