如何覆盖这个父函数?

时间:2016-05-30 14:58:05

标签: wordpress-theming

父主题中的这个功能我无法覆盖它!

add_action( 'header_menu', 'oners_sidebars' );
function oners_sidebars(){
    echo '<a href="#">' . esc_html__( 'Sidebars: ', 'Oners' ) . '</a>';
}

我使用它但不起作用:

function my_addition () {
    echo '<a href="#">' . esc_html__( 'New Text: ', 'Oners' ) . '</a>';
}

function myn_theme_setup () {
    remove_action( 'header_menu', 'oners_sidebars', 1000 );
    add_action( 'header_menu', 'my_addition', 1000 );
}
add_action( 'after_setup_theme', 'myn_theme_setup' );

我该怎么做才能使用我的孩子主题来覆盖它?

请帮帮我

谢谢

1 个答案:

答案 0 :(得分:0)

为什么不删除init中不需要的操作?

function prefix_remove_oners_sidebars(){

    remove_action ('header_menu', 'oners_sidebars');

}

add_action( 'init', 'prefix_remove_oners_sidebars' );

据我所知,wordpress没有名为header_menu的内置动作钩子。您可以查看您的父主题:

do_action( 'header_menu' );

因此,您可以找到它被挂钩的位置,因此您可以删除该挂钩,用适当的挂钩替换我的片段中的init

相关问题