如何删除子主题函数文件中的父主题函数文件过滤器。
功能文件
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');
但它不起作用。
答案 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。