Child Theme – Modify parent theme template file located in subfolder
-
I am using the WordPress default theme “Twenty-fourteen”. The header of this theme is way too narrow and sits to the left, so there is a large empty vertical space at the right (why they made it this way in this day and age I have no idea).
The template I needed to customize is “custom-header.php” which is located in the parent theme subdirectory “inc”. The path is “../wp-content/themes/twentyfourteen/inc/custom-header.php”
I created the child folder and required files (style.css, functions.php) as described in the WordPress Codex page on child themes. The functions.php file contains the following,
<?php add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' ); function my_theme_enqueue_styles() { wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' ); } ?>
I searched for the method to create a copy of the template “custom-header.php” and got so many different methods, all of which failed to work.
I placed a parent copy of “custom-header.php” (with the modifications I made) into the root folder of the child theme, I also tried placing it in duplicate folder structure as the parent (/theme/twentyfourteen/inc) into the child theme (/theme/twentyfourteen-child/inc), both methods failed. The modified template did not work.
I tried to add the following code to the functions.php, along with the above file placement,
require_once( get_stylesheet_directory() . '/inc/custom-header.php' );
but that only created the following error,
Your PHP code changes were rolled back due to an error on line 11 of file wp-content/themes/twentyfourteen-child/functions.php. Please fix and try saving again.
require_once(): Failed opening required ‘wp-content/themes/twentyfourteen-child/inc/custom-header.php’ (include_path=’.:/usr/php/56/usr/lib64:/usr/php/56/usr/share/pear’
All the places I have been via Google resulted in the same information, which has failed to work.
Can someone, hopefully a WordPress developer, explain how I can do this, to include a modified copy of the “custom-header.php” file in the child theme folder and make it work?
Note: Maybe the functions in the function.php are insufficent or incorrect?
- The topic ‘Child Theme – Modify parent theme template file located in subfolder’ is closed to new replies.