Solved

How to find override a php file in a child theme

Posted on 2014-12-12
7
220 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What is the WordPress Exit hook? 1 23
PHP Syntax Error 4 27
Forms that calculate points for wordpress 10 23
Decrypt string by php 7 30
This article discusses how to create an extensible mechanism for linked drop downs.
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 purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…

776 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