Solved

How to find override a php file in a child theme

Posted on 2014-12-12
7
217 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
  • 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

706 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now