I am customising a premium WP theme to suit my site better, but I can't quite figure out what to do with PHP files that I customise. Do they just go into the root of the child theme folder? Or do they get put into a similar folder hierarchy as in the original theme? How do I make sure the child theme PHP file is being used instead of the parent theme PHP file (e.g. header.php)?


3 Answers 3


Couple of things to add

  1. If you add template files on child theme. They will replace the parent theme template files.
  2. CSS doesn't get imported automatically so you have to import them on your child theme css file using @import, It might look something like this @import url("../twentyeleven/style.css");
  3. functions.php file doesn't get replace so all functions from parent theme is still defined and you can add your new php functions on child themes functions.php file.
  4. If you copy and paste a php file from parent theme to child theme for modification and you see something like require_once(TEMPLATEPATH.'/includes/a_php_file.php'); Remember that TEMPLATEPATH constant still points to parent theme directory. If you need to change the file a_php_file.php then copy that file into your child theme too and use themes stylesheet path to get into child theme. So you have to do something like this include( get_stylesheet_directory() . '/includes/a_php_file.php');

So How do I make Sure Child theme file is used: Well, if you do everything right child theme templates already getting used. But still if you want to check you can just add a html comment on the template file and check the source. I do it sometimes when things doesn't work for me also I add the php file name to the html comment so i know which file includes/requires from where.




To take your questions in no particular order:

Any template files you include in a child theme will be used instead of an identically-named parent version automatically. (This doesn't apply to style.css or functions.php, but header.php etc are all covered.)

WP will use the template hierarchy to figure out which templates are needed based on the query in question -- if the theme is well-constructed, you should be fine putting them in the root of your folder without replicating the original directory structure.

BUT, if the parent theme was coded in non-standard ways, and in particular if it tries to include files directly rather than using wp functions (like get_header(), get_footer(), get_template_part() etc.), you may have to get your hands a little dirtier. Good premium themes will often have documentation on how to build child themes for their own systems, especially if they depend a lot on non-wp hooks to get things done... but of course, you may not know until you start playing around how the documentation is on yours. Good luck!


wp function "get_bloginfo"is working for me

<?php echo get_bloginfo('template_url').'/db.php';?>

It can be used inside js code using

url:"<?php echo get_bloginfo('template_url').'/db.php';?>",

working in child theme

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.