WordPress.org

Ready to get started?Download WordPress

Forums

Adding other files to a child theme? (32 posts)

  1. dcloud
    Member
    Posted 3 years ago #

    I have managed to create a child theme, albiet very basic (it just has a stylesheet). But say I've made changes to the main theme (Twenty Ten) in loop.php and functions.php, and a couple other files - how would I include these in the child theme folder?

    I found this on the WP Codex page....

    Other files

    In addition to files such style.css, functions.php, index.php, and home.php, a child theme can use any type of file full-fledged themes use, as long as that file is properly linked. For example, it can use icons and images that are linked from its stylesheet, JavaScript files linked from the top or bottom of pages, or extra PHP files called from templates or from functions.php.

    So how do I "properly link" my other files?

    Thanks.

  2. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

    All you need to do is place your new template and function.php files in the child theme.

  3. dcloud
    Member
    Posted 3 years ago #

    But I don't have a template. Just created a folder and put a style.css file in it. If I try using the other files from my main theme it gives me errors.

    Like I said in my last post - on the Codex web site they said the files should be "properly linked". I want to know how to link them.

  4. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

    If I try using the other files from my main theme

    "Using them" in what way?

  5. dcloud
    Member
    Posted 3 years ago #

    I have some things I've made changes to in other files - like funtions.php, index.php, etc. You can't just stick the whole file in there (in the folder with the child theme) without properly linking it.

    There's a way to do this and that's what I need to know.

  6. demetris
    Member
    Posted 3 years ago #

    dcloud, it depends on what you want to do.

    If you want to use some JavaScript files, for example, you enqueue them from your functions.php using the WordPress Script API.

    If you want to use some extra PHP files for which WP does not offer a standard way, you use the appropriate PHP constructs: include, require, include_once, require_once.

    If you want to use images for your styling, you can link them from your style.css.

    You can go a long way by using just your main CSS file and images linked from it. For the other parts, you can start by reading on:

    First, WordPress templates.

    Second, the WordPress Plugin API. (Which is not just for plugins, but for every piece of code that wants to extend or modify WordPress.)

  7. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

    You can't just stick the whole file in there

    Oh yes - you do. You don't have to "link" to anything. In the case of the child's functions.pp file, it should only contain the modified functions - without the if( function_exists() ...endif conditional.

  8. dcloud
    Member
    Posted 3 years ago #

    Ok, for example......

    I have made a modification to the funtions.php where I inserted my logo over where the text name usually is. Like so...

    <h1 id="site-title">
    <span>
    <a href="<?php bloginfo ('home');?>" rel="home" title="<?php bloginfo('name');?>"/>
    <img src="<?php echo bloginfo ('template_directory');?>/images/ddlogo.jpg" alt="<?php bloginfo ('name');?>" />
    </a>
    </span>
    </h1><!--end of h1 site-title-->

    Now I'm not sure how to make this work as a funtions.php file in the child theme. I tried just putting it between beginning and ending PHP tags, but I get the following error....

    Parse error: syntax error, unexpected '<' in /home/dcloud/public_html/wp-content/themes/twentyeleven/functions.php on line 3

    So I'm not sure how to make these files work. Obviously I need to add some kind of proper link, as the Codex page says. I just don't know how to do it. I'm not a coder.

  9. demetris
    Member
    Posted 3 years ago #

    Sorry. Did not see your last post.

    For index.php: An index.php in a child theme’s folder overrides automatically, just by existing, the parent’s index.php. The same goes for ALL template files. So, you can make something completely different from what the the parent offers, or you can take the parent’s template file and just modify a bit or two in it.

    For functions.php: You can have a functions.php in your child theme containing just the extra bits you want to add. WordPress loads both functions.php files. First the child’s, then the parent’s.

  10. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

    In your example, you need to place a copy of the header.php template file - complete with your modifications - in the child theme.

  11. dcloud
    Member
    Posted 3 years ago #

    In your example, you need to place a copy of the header.php template file - complete with your modifications - in the child theme.

    Yes, but how? You mean place the whole thing in there, just as it is? Sorry, I don't know anything about this stuff.

  12. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

    Copy the parent header.php file into a plain text editor on your machine. Add your modifications and then save the file. Upload it to the child theme using FTP (or whatever file management application your host provides).

  13. dcloud
    Member
    Posted 3 years ago #

    But why would I open the file and make any changes? The file already has my changes in it. I want to keep all the little changes I've made in the different files (within the child theme folder) so they don't keep disappearing every time there's a WP update.

    So again, my question is, how do I place these files (the ones I've made changes in) into the child theme folder without getting the parse and syntax errors?

  14. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

    And where is this amended file?

  15. dcloud
    Member
    Posted 3 years ago #

    There is no amended file. I'll say it again....I have made changes already to files in the Twenty Ten theme (folder). I want to keep these changes so they don't disappear when I update WP or the theme. So what I want to know is how to keep these changes - how do I place these files in the child folder so I can keep the changes?

  16. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

    I want to keep these changes so they don't disappear when I update WP or the theme.

    Then you have to create a child theme. You shouldn't have amended Twenty Ten in the first place.

  17. dcloud
    Member
    Posted 3 years ago #

    I have created a child theme. Nevermind......I will wait until someone can actually help me.

  18. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

    If your modified files are in the child theme and you are using the child theme, your changes will not be over-written. You do not need to "link to" anything for a properly constructed child theme to work.

  19. demetris
    Member
    Posted 3 years ago #

    dcloud,

    You need to help others help you. You can do this by doing some work yourself first: just read the documentation carefully.

    The concept and the workings of child themes are simple, and the documentation is plentiful and of good quality. So, take some time to look at it again, and you will see that you will understand better and that others will be then able to help you more efficiently.

  20. dcloud
    Member
    Posted 3 years ago #

    I have read the documentation, but I am not a coder and so none of it makes any sense to me. That's why I came here to ask my questions. All I want to know is what they mean by "...as long as that file is properly linked."

    I want to keep the changes I've made to the Twenty Ten files, so I don't loose them with any updates. But I don't know how to save any other files but the CSS one. That's why I came here, to ask about this.

  21. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

    Template: twentyten

    That's the link! It's in the header block of the child theme's style.css file.

  22. dcloud
    Member
    Posted 3 years ago #

    I guess I'll have to look elsewhere for help.

  23. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

    It was also pointed out to you in another thread that there is a known bug related to numeric theme and/or theme folder names: http://wordpress.org/support/topic/child-theme-not-working?replies=10

  24. dragonsjaw
    Member
    Posted 3 years ago #

    ok let me jump in here and muddy up the waters a bit more.

    Let's be clear..you made changes to the default Twenty-ten theme on the functions.php page, correct?

    So the easiest way to get those changes into the Child theme would be to
    1) copy the default Twenty-ten functions.php file to a plain text editor
    2) find the functions You Changed in that file
    3) make a new file called functions.php (for your child theme)in the plain text editor and add the functions you changed
    4) upload (ftp) the new functions.php to your child theme folder.

    The above process can be used to save all the changes you have made.
    Don't remember where they all are..
    then either download the default Twenty ten files to your computer, or copy and paste them from the editor to your computer. (so you can save your changes)

  25. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    if you can't or don't want to work with child themes, there is another way:

    create a new sub-folder of the /themes folder; name it somehow related to your intended theme name (as you know now, no pure numerical folder name);
    for instance: /wp-content/themes/twentyeleven

    then copy all theme files from the Twenty Ten (which you are modifying), into the new folder;

    then rename the theme in style.css (for instance):

    /*
    Theme Name: Twenty Eleven
    Theme URI: http://wordpress.org/
    Description: 2011, based on Twenty Ten, the default theme for WordPress.
    Author: the WordPress team; modified by dcloud
    Version: 1.0
    Tags: black, blue, white, two-columns, fixed-width, custom-header, custom-background, threaded-comments, sticky-post, translation-ready, microformats, rtl-language-support, editor-style, custom-menu (optional)
    
    License:
    License URI:
    
    General comments (optional).
    */

    http://codex.wordpress.org/Theme_Development
    http://codex.wordpress.org/Theme_Development#Theme_Stylesheet

    that is all - you can now edit and modify this theme as you like - it will not be overwritten with any update

    (make regular backup copies of your themes and database)

  26. dragonsjaw
    Member
    Posted 3 years ago #

    That is what I was thinking and trying to explain, but you did a much better job.

  27. dcloud
    Member
    Posted 3 years ago #

    I apologize to everyone. I was getting frustrated. I thank all of you for taking the time to help. alchymyth, thank you for that post. I'm going to give that a try.

    After I do this should I "activate" that theme in the Themes area of my dashboard? And forgive me if this sounds dense, but will the new theme keep the changes on the site even if I have to update the original theme?

  28. dcloud
    Member
    Posted 3 years ago #

    Also if I do create my own theme off the original will the updates to the original theme have any effect on the one I created? I'm just wondering if the created theme will update along with the original.

  29. dcloud
    Member
    Posted 3 years ago #

    Hello?

  30. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

    If your new theme is a child of the original, your customisations will be preserved when upgrading the original but you should be able to take advantage of any new theme functionality.

    If your new theme is a standalone theme, it will not be affected in any way by any updates in the original theme.

Topic Closed

This topic has been closed to new replies.

About this Topic