Risposte:
C'è un'azione get_headerche puoi usare. Nel tuo tema functions.php, registra un callback per quell'azione:
add_action( 'get_header', function( $name ) {
add_filter( 'current_header', function() use ( $name ) {
// always return the same type, unlike WP
return (string) $name;
});
});
Puoi anche scrivere una piccola classe di supporto che puoi riutilizzare:
class Template_Data {
private $name;
public function __construct( $name ) {
$this->name = (string) $name;
}
public function name() {
return $this->name;
}
}
add_action( 'get_header', function( $name ) {
add_filter( 'current_header', [ new Template_Data( $name ), 'name' ] );
});
Nel tuo header.php, ottieni la parte / nome corrente con:
$current_part = apply_filters( 'current_header', '' );
Puoi fare lo stesso con get_footer, get_sidebare get_template_part_{$slug}.