Where to put custom PHP files in a child theme?

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.

Codex:

http://codex.wordpress.org/Function_Reference/get_stylesheet_directory

Leave a Comment