Support » Themes and Templates » Child Themes and PHP pages

  • Resolved goldmember


    in all the tutorials, everyone seems to be saying that you only edit the CSS file to create the child theme, and it just pulls all the PHP files, verbatim, from the parent.

    But what if i’ve made a lot of changes to the PHP files? For instance, often I remove the Comment section code from the PHP files because I do NOT want that functionality on the site.

    So what do I do in these instances??? How does one handle editing the PHP files???? I understand how it works with the CSS file, in that the child CSS classes override the parent CSS classes. But i’m lost when it comes to what happens with the PHP????

Viewing 15 replies - 1 through 15 (of 15 total)
  • You create a css file, with a reference to the parent, import the parents style.css, add a screenshot.png and if you need to a functions.php.

    Copy across only the template files you want to change and make your changes in the child themes directory, if you wanted to change header.php then copy this file across, as you say any style changes make them in the child themes style.css and they override the parents, same with templates.

    If you add a file or image to the child themes directory, and want to include it in then calls to TEMPLATEPATH are replaced with STYLESHEETPATH, calls to get_bloginfo(‘template_directory’) are replaced with get_bloginfo(‘stylesheet_directory’).

    $imagepath = STYLESHEETPATH .'/images/headers/';
    $imageurl = get_bloginfo('stylesheet_directory');

    General Comments for anyone reading this:
    Advantages are where changes made to the default theme will be overwritten by the latest release, the child theme will not be affected.

    Example of style.css twentyten parent.

    Theme Name: your child theme name
    Theme URI: website for your theme
    Description: your description seen when you select the theme
    Author: name or website name
    Author URI: your website
    Template: twentyten
    Version: V1.1.1
    Tags: add your tags here
    @import url('../twentyten/style.css');
    /* Changes and Additions Digital Raindrops
    add image margin top and right */
    #content img {
    	margin: 10px 10px 0 0;


    More Reading

    so if i understand you correctly, the child PHP pages will overwrite the parent PHP pages, just like the child CSS page overwrites the parent CSS page??????????????

    Yep thats right, but only pull across the page files you want to edit not all of them, any new templates create in the child themes folder, and theme images changes the same, the rest are inherited by the child theme.

    so if the way to get the child CSS to overwrite the parent CSS is to put the code below at the top of the child CSS file…

    Theme Name: your child theme name
    Theme URI: website for your theme
    Description: your description seen when you select the theme
    Author: name or website name
    Author URI: your website
    Template: twentyten
    Version: V1.1.1
    Tags: add your tags here
    @import url('../twentyten/style.css');

    …then how do I get the child PHP pages to overwrite the parent PHP pages? what setting or code do i need to put and where???

    None, they only need to exist in the child themes folder, WordPress will then read them first and ignore the parent, same as the style.

    This line in the css ‘Template: twentyten’ tells WordPress where to read the parents themes files from if they do not exist in the child.

    I have only been using child themes for a couple of weeks and had more than a few problems getting my head around it at first, but a child theme can just be the style.css with a couple of changes, or with it’s own additional template files, modified files copied from the parent and changed, and optional a functions.php with new functions.

    Just copy across one file like header.php make a small change that will dispalay and test it, you will understand better when you get hands on.

    David 😉

    from what i’ve been reading, people seem to say that i should be creating a functions.php file. but i don’t quite understand how to make use of it. ideally i dont want to have to create individual files for all the parts of the theme that i typically butcher (i.e. header.php, footer.php,… well all of them really) because when a new version of a theme comes out and i update the parent, how will i know what lines of the child to keep, what to add, and what to delete???

    so let’s say i wanted to do something standard, like delete comments functionality from my Posts.

    normally, I would go to my single.php file and remove the line that says <?php comments_template( '', true ); ?>.

    So what exactly would I do in this new functions.php file that resides in my child-theme folder, with the goal in mind of cancelling out the <?php comments_template( '', true ); ?> in the single.php file in my parent folder, but not touching that file?

    Because after all, the purpose of the child theme is to do things that won’t be overridden when I update the theme later on.

    please advise. thanks!

    Hi it is good that you are keeping child themes as an option and feeding back for others.

    Point 1:
    If you only want to re-style the theme then you do not need the functions.php file, you would only use this to override parent theme functions with your own or add new custom functions.

    As an example in the twenty ten theme, there is one menu theme location, so in my child themes functions.php I unload this and load three menus of my own, the headers list is hard coded not something I would normally do, I unload the twenty ten select headers code from the parent, then loop through the child themes /images/headers/ folder which has my own headers and load these in code, now I can add headers without writing any more code, and this is all done from the childs functions.php.

    Point 2:
    This is exactly what the child theme is for, you would do the following, no need to create just copy and paste the single.php from the parent themes folder to the child themes folder, then open the child themes single.php and make your changes.

    When the child theme runs it will use all page files from the parent unless they exist in the child, so your new child themes single.php without the comments will be loaded.

    As you have preserved the original single.php when the twenty ten theme has another release your changes will not be overwritten or affected, you can then look to see if the single.php was updated in the parent (twenty ten) and decide if to take the changes across, if the comments had changes you would not.



    thanks david for bearing with me here.

    1) when a new version of the twentyten theme comes out, how will i know which php files changes, and what changed about them?

    2) is there any easy way to cancel out PHP code rather than delete it? that way it will be a lot easier to compare the differences between my version and the original. for instance, if i wanted to get the comments section to stop from working in my child single.php file, could i edit that line of code in any way to prevent it from functioning, but still keep it in place??

    for instance
    <?php XXX-STOP-WORKING-XXX comments_template( '', true ); ?>

    as a followup, it seems to me like creating a new functions.php file is ONLY to ADD actions, not cancel them out???

    1) The author will in most cases post a change log, and identify the changed files, you would keep a copy of say the current twenty ten, and when a vew version comes out read the release notes and any pages you have changes compare the un-edited files of the two twenty ten releases, then decide if the changes should go over.

    2) Remark the code out and add a note!

    <?php /* these are the php remarks */ ?>
    <!-- These are HTML remarks -->
    <?php /* Disabled by DSC 040810  comments_template( '', true ); */ ?>

    3) You can remove filters and actions in the Parent and replace these with your own, example functions.php remove the one menu loacation and add three.

    add_action( 'after_setup_theme', 'my_custom_setup' );
    if ( ! function_exists( 'my_custom_setup' ) ):
    function my_custom_setup() {
    	// Unregister the default menu
    // This theme uses wp_nav_menu() in three location.
    register_nav_menus( array(
    	'primary' => __( 'Main Menu', $themename ),
    	'secondary' => __( 'Top of Page Menu', $themename ),
    	'tertiary' => __( 'Sidebar Menu', $themename ),
    ) );

    This is as far as I can take this topic, best move now is to try things out.


    that’s perfect. thank you!

    Good resource of good questions and sound answers.

    David, you’re a good man!

    ADeptris, your advice is absolutely wrong. it doesn’t work. I tried it, but then there’s strings and code at the top of my site. Clearly, you cannot simply “copy across” php to the child theme, there must be something else one must add first, otherwise your site loads with all those ugly strings and codes at the top above the banner.

    So does anyone here have actual and useful advice or not?



    This thread was the perfect one for me. I was just looking for what goldmaster had in mind. Same thoughts and questions.!

    Thanks all.


    It was perfect for me too… to dig deeper and continue to make this conversation even more useful for others…..

    What is the relationship between the “discussion -> Allow Comments” option in editing mode and the php call:
    <?php /* comments_template( ”, true ); */ ?> ?

    I would prefer to leave this line in my templates and let users choose whether or not to allow comments in editing mode but toggling that option on and off doesn’t seem to matter if this line is in the template file.

    Help would be appreciated

    PS. I’m making a child theme for TwentyTen

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Child Themes and PHP pages’ is closed to new replies.