使用子主题函数从父主题中删除_action。php

时间:2021-02-16 作者:AdrobaT

我正在尝试从父主题标题中删除一个操作,但仍然没有成功,下面是类

<?php

class theme_Header_Layout{
    public function __construct() {

        add_action(\'theme_header_layout_1_branding\', array( $this, \'get_site_branding\' ), 10 );

        add_action(\'theme_header_layout_1_navigation\', array( $this, \'get_site_navigation\' ), 10 );

        add_action(\'theme_site_header_icon\', array( $this, \'get_site_header_icon\' ), 10 );

        add_action(\'theme_site_header\', array( $this, \'site_skip_to_content\' ), 5 );

         *
         *
         *
        add_action(\'theme_site_header\', array( $this, \'site_hero_sections\' ), 9999 );
    }
    *
    *
    *
    public function site_hero_sections(){...}
    function hero_block_heading() {...}
    private function alowed_tags(){...}
}

$theme_header_layout = new theme_Header_Layout();
这就是我的主题子函数。php

<?php

    add_action( \'wp_enqueue_scripts\', \'theme_enqueue_styles\' );
    function theme_enqueue_styles() {
        wp_enqueue_style( \'parent-style\', get_template_directory_uri() . \'/style.css\' );
    }

    add_action( \'wp_head\', \'remove_site_hero_sections\');
    function remove_site_hero_sections() {
        global $theme_header_layout;
        remove_action(\'theme_site_header\', array($theme_header_layout, \'site_hero_sections\'));
    }
我一直在尝试更改add\\u action或remove\\u action中的优先级,我还尝试更改add\\u action(\'wp\\u head\'…)到“theme\\u site\\u header”,但我仍然得到关于我的孩子主题的site\\u hero\\u部分,我做错了什么?

1 个回复
最合适的回答,由SO网友:AdrobaT 整理而成

好吧,我所需要解决的问题就是为remove\\u操作添加完全相同的优先级,由于Sally CJ的回答,它工作得非常好

add_action( \'wp_head\', \'remove_site_hero_sections\');
    function remove_site_hero_sections() {
        global $theme_header_layout;
        remove_action(\'theme_site_header\', array($theme_header_layout, \'site_hero_sections\'), 9999);
    }