Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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)?

share|improve this question
1  
Recommended Reading: codex.wordpress.org/Child_Themes –  its_me Jul 13 '12 at 3:59
add comment

2 Answers

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!

share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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