remove_action from parent theme using child theme functions.php

I am trying to remove an action from the parent theme header but I am still not getting any success, here is the class

<?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();

And this is what I have on my theme-child functions.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'));
    }

I’ve been trying changing the priority inside add_action or remove_action, I’ve also tried changing the add_action(‘wp_head’…) to ‘theme_site_header’ but I am still getting the site_hero_sections on my child theme, what am I doing wrong?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Well, all I needed to fix the issue was to add the exact same priority to the remove_action and it worked pretty well, thanks to Sally CJ answer

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);
    }


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x