我有一個主題是通過jQuery添加一個自定義的全屏幕背景圖像。主題是通過稱爲td_background
的class
對象完成的。在這個類中有一個叫wp_head_hook()
的函數,在這個鉤子中,爲自定義bg添加了一個過濾器。它看起來是這樣的:WordPress remove_filter()通過插件刪除主題JS鉤子
class td_background {
// ..some stuff
function __construct() {
add_action('wp_head', array($this, 'wp_head_hook'), 10);
}
function wp_head_hook() {
add_filter('td_js_buffer_footer_render', array($this, 'add_js_hook'));
}
function add_js_hook($js) {
// Custom JS added here for background image
return $js
}
}
new td_background();
我現在嘗試在自定義插件我寫取消註冊add_js_hook
,但我有麻煩纏繞我的腦海裏圍繞着如何與這一切嵌套做到這一點。我已經嘗試了一些東西,比如:
<?php
// This...
remove_filter('wp_footer', array($td_background, 'td_js_buffer_footer_render'));
// ...and this
remove_filter('wp_footer', 'td_js_buffer_footer_render');
// ...and even
remove_filter('wp_footer', 'add_js_hook', 100);
?>
我也試着改變以上wp_head
。
想法?我的最終目標是在頁腳中註銷此JavaScript,以便我可以添加自己的代替它。
它正在匿名實例化,你會[需要這個](http://wordpress.stackexchange.com/questions/57079/how-to-remove-a-filter-that-is-an-anonymous-object/57088#57088) – brasofilo 2014-10-20 16:56:01
很酷的信息,但似乎並沒有...至少我沒有看到這被列爲匿名函數。 – rnevius 2014-10-20 19:56:41