Solved

How to find override a php file in a child theme

Posted on 2014-12-12
7
222 Views
Last Modified: 2014-12-12
I am using a child theme of a premium theme and I want to override some of the code in one of the parent theme's framework files. It's a simple change and I've tested it on the actual fine in the parent theme to make sure my changes are good, but then when I move those changes to my child theme in the same folder path, my child theme is not picking up the edited copy of the file.

For example - the file I want to change is /ParentTheme/framework/page-header.php. I want to replace it with /ChildTheme/framework/page-header.php. So I copied the file, made the changes and then added this to my child theme functions.php:

require_once( get_stylesheet_directory() .'/framework/page-header.php');

Open in new window


I also removed any "if ( ! function_exists( 'functionname' ) ) {" statements in the edited copy in my child theme so it should override the parent theme. However, this still isn't working. The site still displays the parent code. I even copied the whole code into my child functions.php file and it still isn't overriding the parent code. Where else should I be looking or what else can I do to force it to override?

Thanks in advance!
0
Comment
Question by:techbots
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 40497224
You shouldn't have to add that line of PHP to make it work (and it's probably breaking because get_stylesheet_directory() is resolving to the wrong place for a theme template).

Instead, just add page-header.php to the child theme.  Child themes look in their own directory for templates first, then go back to the parent theme if something isn't found.

Ref: http://codex.wordpress.org/Child_Themes#Template_Files
0
 
LVL 1

Author Comment

by:techbots
ID: 40497242
Thanks Jason - I removed that line but the child page still isn't overriding the parent. I had used this theme before and had to add that code to override a page, but it isn't working in this case. So frustrating. Is there something I should be looking for in the parent theme, like perhaps the page being called from another page, that could be causing the issue?
0
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 500 total points
ID: 40497258
like perhaps the page being called from another page, that could be causing the issue?

Yup.  If the file page-header.php is called from header.php using get_template_part() or as an include, WordPress will use header.php's location as the source.

Possible solution to the hypothetical above: copy header.php to the child theme (no need to modify it), modify child theme's page-header.php as desired.

What theme is this?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:techbots
ID: 40497427
The theme is Total by WPExplorer. It's a great theme, but this has had me stumped. I will try what you suggested and see if that works. Thanks!
0
 
LVL 1

Author Closing Comment

by:techbots
ID: 40497458
Though no the complete solution to my problem, this helped considerably in narrowing down the issue and coming up with a working solution.
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 40497463
What did I miss? Fill in the blanks so I can answer better next time...
0
 
LVL 1

Author Comment

by:techbots
ID: 40497487
Jason - you didn't miss anything. You gave a good solid answer. But my problems just ended up being more than my original question so I guess I worded that wrong. You gave a complete answer - I didn't ask the complete question because I figured some of the rest of it out once you got me started. You got an A!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question