如何在子主题函数文件中删除父主题函数文件过滤器

时间:2015-11-06 06:39:43

标签: php wordpress wordpress-theming

如何删除子主题函数文件中的父主题函数文件过滤器。

功能文件

function add_opengraph_doctype( $output ) {                                            

    return $output. ' prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb#"';
}
add_filter('language_attributes', 'add_opengraph_doctype');

我尝试删除像

这样的子主题
remove_filter('language_attributes', 'add_opengraph_doctype');

但它不起作用。

2 个答案:

答案 0 :(得分:4)

子主题的functions.php文件将在父级之前运行,因此它尚未注册。

您可以等待init操作删除过滤器。

function remove_language_attributes() {                                            
    remove_filter('language_attributes', 'add_opengraph_doctype');
}
add_filter('init', 'remove_language_attributes');

答案 1 :(得分:0)

您可以在此过滤器中设置优先级:

 add_filter('language_attributes', 'add_opengraph_doctype', 10);

并将子设置为过滤优先级大于10。