Solved

How to find override a php file in a child theme

Posted on 2014-12-12
7
221 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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 Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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!
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
The viewer will learn how to dynamically set the form action using jQuery.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

789 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