wordpress child theme: how to overwrite template .php files

723

I have a child theme setup in wordpress and the style.css and functions.php in the child theme are working correctly. I now want to overwrite other template .php files with the versions in the child theme. I can't seem to make these files overwrite the parent theme however.

child theme functions.php:

<?php
//enqueue styles
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles', 'overwrite' );
function theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );

}
//overwrite template pages
function overwrite() {
    wp_enqueue_script( get_template_directory_uri() . '/inc/structure/hooks.php' );
    wp_enqueue_script( get_template_directory_uri() . '/inc/structure/header.php' );
}

I have a hooks.php and header.php in /child-theme/inc/structure/

673

Answer

Solution:

For a child-theme you do not need to enqueue any template (PHP) files, simply add a PHP file to your child-theme with exactly the same name and path as the one you are trying to overwrite in your parent theme and it will naturally replace it.

People are also looking for solutions to the problem: Facebook Graph API - PHP - Can't post to certain pages

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.