I was wondering how can I load parent theme template parts through child theme after customization. I have created three custom template for my theme and they are working fine. But now I want to load parent theme template parts layout. For example if I want edit profile page the location of the PHP file in parent theme is template_parts/layouts/profile/profile-modern.php In that folder there are other parts profile-header.php and other files. I tried to edit the profile-mordern.php directly in the parent theme and it works. But after theme update, it will be gone so I want to load that file from my child theme. I tried to search the solution but didn't get any specifically. Please can anyone help me regarding this issue? And I am learning PHP programming and WordPress theme customization so please guide me step by step if possible. And also resource link to learn.

  • 1
    Just copy parent_theme/template_parts/layouts/profile/profile-modern.php file to child_theme/template_parts/layouts/profile/profile-modern.php.
    – Amir
    Apr 24 '20 at 5:38

For every theme file present in the parent directory, WordPress will check whether a corresponding file is present in the child theme and, if so, use that one instead. This means that a profile-modern.php file in the child theme will override its equivalent in the parent folder.

So, if you don’t like something about a page’s layout, just copy the respective file, implement your changes, and upload it to the child theme’s folder. The modifications will then appear in the child theme, while the original file will remain untouched.

  • You should create path exactly like parent theme.
    – Amir
    Apr 24 '20 at 6:22
  • "For every theme file present in the parent directory" This is not correct. This only applies to certain files and functions. WordPress itself only checks for template files in the template hierarchy and some other partial templates. For a child theme to load other files the parent must use certain functions. For example, get_template_part() will search the child theme, but include will not. Neither will get_stylesheet_directory_uri(), but get_them_file_uri(); will. Apr 24 '20 at 7:12
  • @JacobPeattie so how can I load the template layouts? Apr 24 '20 at 11:58
  • If your parent theme uses get_template_part() correctly, then just copy the files into the same folder in your child theme. If that doesn't work it might not be possible. You should check with the theme author. Apr 24 '20 at 13:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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