I was having the same problem with some php functions. I guess my solution would work for javascript functions too, but I haven’t tried it. However, here is the layout:
In my case, it was a matter of modifying some functions that the parent theme (https://www.graphene-theme.com/) used by calling files from an “includes/” dir. For example modifying a function that adds a “Continue reading” link button to search results.
Thus, if the included files only contain functions, an easy fix is then just to overwrite the functions in the parent theme by requiring a file with the functions you want to override in the child theme’s function.php and making sure that all the if(!function_exists(‘some_random_function’)) nestings are removed (so that you force an override).
Example:
Let’s say your parent theme has a “theme_name/includes/function_script_to_override.php” file that you want to override.
- Create a copy of the file you want to override (theme_name-child/includes/function_script_to_override.php) in your child theme.
- Then make sure that all the functions called in your child theme’s modified function_script_to_override.php are not nested in if(!function_exists(‘some_random_function’)) cases.
For example, the function:
if (!function_exists('graphene_continue_reading_link')) {
function graphene_continue_reading_link() {
Do something here...
}
}
becomes just
function graphene_continue_reading_link() {
Do something here...
}
- Then insert this line in your child theme’s function.php:
require_once( get_stylesheet_directory() . '/includes/function_script_to_override.php' );
Because the functions.php in your child theme is loaded right before the parent’s file, your modified function_script_to_override.php will be included after the original (which still should have the if(!function_exists cases) thus overwriting these functions.
I hope it helps someone.