How to load ‘custom-header.php’ from child theme

So I’ve created a child theme in WordPress, and everything works as it should except for the custom-header.php. I wish to use the one in the child theme, not the one in the parent theme. I am doing this by attempting to call it from the functions.php file in my child theme. I have my child theme’s custom-header.php file in an inc folder, but have tried it in the main directory with the rest of the files.

My Code (functions.php)

* Enqueues child theme stylesheet, loading first the parent theme stylesheet.
function nisarg_custom_enqueue_child_theme_styles() {
wp_enqueue_style( 'parent-theme-css', get_template_directory_uri() . '/style.css' );
/* Problem Code Below */
require_once( get_stylesheet_directory() . '/inc/custom-header.php' );
add_action( 'wp_enqueue_scripts', 'nisarg_custom_enqueue_child_theme_styles', 11 );

The Problem

The problem is this line: require_once( get_stylesheet_directory() . '/inc/custom-header.php' ); Whenever I put any require_once statement in my functions.php file, the entire website goes blank.

My Question

How can I load my child theme’s custom-header.php instead of the parent theme’s?

Read more here: How to load ‘custom-header.php’ from child theme

Leave a Reply

Your email address will not be published. Required fields are marked *