WordPress : remove_action du thème parent en utilisant le thème enfant functions.php
J’essaie de supprimer une action de l’en-tête du thème parent mais je n’obtiens toujours aucun succès, voici la classe
<?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();
Et c’est ce que j’ai sur mon 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'));
    }
J’ai essayé de changer la priorité dans add_action ou remove_action, j’ai aussi essayé de changer add_action(‘wp_head’…) en ‘theme_site_header’ mais je reçois toujours le site_hero_sections sur mon thème enfant, qu’est-ce que je fais de mal ?
Solution n°1 trouvée
Eh bien, tout ce dont j’avais besoin pour résoudre le problème était d’ajouter exactement la même priorité à l’action remove_action et cela a plutôt bien fonctionné, grâce à la réponse de 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);
    }
0 commentaire