• Resolved VladislavV

    (@vladislavv)


    On the Child theme Codex page stated:

    “If you want to change more than just the stylesheet, your child theme can overwrite any file in the parent theme: simply include a file of the same name in the child theme directory, and it will overwrite the equivalent file in the parent theme directory. For instance, if you want to change the PHP code for the site header, you can include a header.php in your child theme’s directory, and that file will be used instead of the parent theme’s header.php.”

    I have a files called post-types.php and register-sidebars.php files in the parent theme that are called by the parent functions.php:

    require_once("includes/post-types.php");
    require_once( "includes/register-sidebars.php" );

    I copied these files in the same directories in the child theme. Now they are showing in the Appearance > Editor, but when I make changes in the child theme files, these changes do not take effect at all. When I change the parent files, on the other hand, the changes applies.
    I need to make minor changes to these files, but within my child theme, so I could update my parent theme in the future without any problems.

    Thank you for your help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Unfortuantely your theme is not doing things in the right way, so you’re going to have troubles. The themes authro should have used something like this instead…

    require_once (get_stylesheet_directory_uri() . 'includes/post-types.php')

    That would retrieve the file from the current theme. There’s more to it then just that line of code though so it’s not as easy a fix as it seems.

    To get around the problems, you’ll need to create a new functions.php file in your child theme, and copy the function that has those require_once() statements into it That way the child theme will use that function and include the correct files. BUT… I’m going to guess that the parent theme doesn’t wrap the functions in a test block which it should. It should look something like this:

    if (!function_exists ('function_name')) {
        function function_name () {
            // Code goes in here.
        }
    }

    if the function doesn’t have the if() around it in the parent theme, then it won’t work because you can’t define two functions with the same name.

    If that’s the cae you’ll need to go back to the themes author and seeif they can fix either (or both) of these issues for you and then they’ll be available in a future update.

    Unfortuantely there’s a lot of possible problems with creating a theme that’s going to be used as a parent, as most of the public themes are. Not many authors get it all right, but they learn as they go along, so if you can raise the issues (in a nice way of course) withthe author, it will help them to learn more, and everyone that uses that theme from then on will benefit as well.

    Thread Starter VladislavV

    (@vladislavv)

    Thank you so much for your help. You’re great!

    I’ve tried so many things and looked over lots of blogs to find the answer. I couldn’t find it which simply means that the problem is not a global one.

    I asked the author for help now. I’ll post if there will be any helpful information.

    Thanks again.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Child theme overwriting flies problem’ is closed to new replies.