Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to find override a php file in a child theme

Posted on 2014-12-12
7
Medium Priority
?
229 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 2000 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
Technology Partners: 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

Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

Question has a verified solution.

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

In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
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.

722 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