我有以下功能在父functions.php文件坐:在儿童主题删除WordPress的功能
#-----------------------------------------------------------------#
# Site Title
#-----------------------------------------------------------------#
function theme_slug_setup() {
add_theme_support('title-tag');
}
add_action('after_setup_theme', 'theme_slug_setup');
if (! function_exists('_wp_render_title_tag')) {
function theme_slug_render_title() { ?>
<title><?php wp_title('|', true, 'right'); ?></title> <?php
}
add_action('wp_head', 'theme_slug_render_title');
}
我想首先的禁用它,然后尝试和我的孩子函数文件将其替换...
我已经试过这个取代它:
add_action('after_setup_theme', 'theme_slug_setup');
function theme_slug_render_title() { ?>
<title><?php wp_title('|', true, 'right'); ?></title> <?php
}
add_action('wp_head', 'theme_slug_render_title');
或这些将其删除:
function child_remove_parent_function() {
remove_action('after_setup_theme', 'theme_slug_setup');
}
add_action('wp_loaded', 'child_remove_parent_function');
function child_remove_parent_function2() {
add_action('wp_head', 'theme_slug_render_title');
}
add_action('wp_loaded', 'child_remove_parent_function2');
但我似乎无法得到任何工作!有人能够指出我要出错的地方吗?谢谢!
++++++++++++++编辑++++++++++++++
我不得不添加另一个函数内部的remove_action码 - 这工作对自己并删除标题标签...
add_action('after_setup_theme', 'remove_head_title', 0);
function remove_head_title() {
remove_action('wp_head', 'theme_slug_render_title');
remove_action('after_setup_theme', 'theme_slug_setup');
}
看看,所以你会更清楚地通过子函数替换父函数:https://wordpress.stackexchange.com/questions/95799/is-it-possible-to-disable-a-function-ofa-a-父主题 –
谢谢Fabien - remove_action行是否需要在自己的函数中?由于这不起作用,它似乎没有任何效果...... –
不,“remove_action”函数必须直接在文件中(不在其他函数中)。初始代码中的问题可能是因为您在其他操作中调用了您的'remove_action'(这太迟了)。我的编辑更清楚了吗? – Fabien