I’ve been searching for a proper solution to override functions and hooks in my parent theme’s functions.php.
My parent theme has:
define('TS_INC', TEMPLATEPATH .'/inc');
require_once( TS_INC .'/file1.php');
require_once( TS_INC .'/file2.php');
I want to have in my child theme an /inc folder with file2.php changed according to my needs.
This means that I want every call to file1.php to reach the parent theme /inc folder and calls to file2.php to go to my child/inc folder.
Thanks in advance.
You can only override functions in a Parent Theme if the Parent Theme makes functions pluggable (by wrapping them in an
if ( ! function_exists( 'function_name' ) )
conditional), or if the output of a function is passed through a filter (e.g.return apply_filters( $filter_name, $function_output );
functions.php
file, simply define a function with the same name as the pluggable function you want to override. This is often the case with, for example, a Theme’s setup function, e.g.twentyeleven_setup()
.functions.php
file, define a callback, and then calladd_filter( $filter_name, $callback );
If the Parent Theme doesn’t provide either of these two methods, then the Parent Theme’s functions cannot be overridden in a Child Theme.
Edit
Just for kicks and grins, since WordPress loads the Child Theme’s
functions.php
file immediately before the Parent Theme’sfunctions.php
file, try adding the following to your Child Theme’s functions.php:It’s worth a shot, anyway.