8

I have created a child theme.

In the parent theme there is a file functions_custom.php, which has some functions definitions. The file included in functions.php in the parent theme.

Now I want to make some changes in one function that's in the functions_custom.php file and the function used in single.php to echo some dynamic content.

So how to override that function in child theme?

3 Answers 3

8

I am not sure if the function in the functions_custom.php that you wants to override is a pluggable functions like below:

if ( ! function_exists ( 'function_name' ) ) {
    function function_name() {
        // Function Code
    }
}

If it is pluggable function then you can simply write function with same name in your child theme and WordPress will run the Child Theme function first.

2
  • I want to override that function in child theme and your answer will create definition in case function not exist. May 1, 2017 at 7:12
  • You misread the answer. In many themes, the function can easily be redefined because the developer has written the functions the way stated above. It means the original function of the theme will only be called when there is no function by that name defined elsewhere, e.g. in the child theme
    – RST
    May 28, 2017 at 9:20
0

You can simple copy the functions_custom.php in your child theme and do whatever in the this file.

3
  • Hello, I tried but it is not working, the file is included in functions.php in parent theme and it always takes parents directory's functions_custom.php file's functions definition. And If try to include child theme file in child theme functions.php then it return error for duplicate definition of one function. May 1, 2017 at 7:11
  • Have you tried also add single.php also in child theme
    – Tarun modi
    May 1, 2017 at 7:54
  • single.php already in child theme, but not working. May 1, 2017 at 9:14
-1

If it's not pluggable. you may want check this question/answer:

How to override parent functions in child themes?

2
  • Hello, as I said functions_custom.php has a function definition it is not added to any filter, and that function used directly on single.php file to echo some dynamic content. then how to remove and add filter for that function? May 1, 2017 at 7:09
  • @VinayaMaheshwari it sounds like you can't overwrite the function, but you could define your own if it's being used in a template file (single.php) and then copying and editing that template file in your child theme. You would then just change their function to your function call in that template file, and WP template hierarchy will load that one instead. May 2, 2017 at 21:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.