-
AuthorPosts
-
March 25, 2014 at 7:02 pm #242940
I was trying to look after a way to override included files into the main template folder from a child theme. I found this post on worpdress forums, and it would be great that this theme can include this. Maybe is a huge job to change almost all the theme, but it will give a huge opportunity to change the skin in case we need or add new features to the theme.
I quote it here:
One of the biggest limitations of child themes right now is that only the child theme’s template files are automatically loaded. If you want to override a file that the parent theme includes (e.g., themedir/lib/foo.php) then you have to find the file that calls require_once(TEMPLATEPATH . ‘/lib/foo.php) and override it to call require_once(STYLESHEETPATH . ‘/lib/foo.php), and in some cases you have to do that 3 or 4 times until you get to the top of the hierarchy.
It’d be better if there were some kind of wp_require_once() function that would take a path (relative to the theme dir), and then check if there was a child theme file to replace the parent theme one.
function wp_require_once($path)
{
if( TEMPLATEPATH != STYLESHEETPATH && is_file(STYLESHEETPATH . $path) )
require_once (STYLESHEETPATH . $path);
else
require_once (TEMPLATEPATH . $path);
}Then theme developers could use wp_require_once(‘lib/foo.php’) instead of require_once(TEMPLATEPATH . ‘lib/foo.php’). If a child theme was being used and had a replacement file, WP would load it; otherwise it would load the parent file.
March 26, 2014 at 10:34 am #243245Hey Pedro!
This will most likely not ever happen unless WordPress core offers an implementation of it. There are actions and filters in place when a theme author wants to offer flexibility on sections and get_template_part for fully replacing files. On top of that there is
if(!function_exists
so that you can replace functions which are meant to and planned to be replaced.With Enfold specifically, you can already completely overwrite the parent files by setting the use_child_theme_functions_only to true which lets you then include everything yourself.
At that point however you would be better off modifying the parent theme by forking it using something like git. Then track any changes and merge them into your new branch.
Best regards,
DevinMarch 26, 2014 at 10:44 am #243252Thanks for the explanation ;)
-
AuthorPosts
- The topic ‘Ability to override included files in child themes’ is closed to new replies.