1

Most if not all of the answers to this question are pretty old, or are for edge cases.

I have a child theme for a commercial theme ("Total"). The parent theme's functions.php loads functions from several php files in its "framework" folder. The function I am targeting is in fonts.php, called wpex_standard_fonts:

if ( ! function_exists( 'wpex_standard_fonts' ) ) {
function wpex_standard_fonts() {
    return array(
        "Arial, Helvetica, sans-serif",
        "Arial Black, Gadget, sans-serif",
         ...
         );
   }
}

So, from what I have googled, I take this add to my child theme functions.php with my changes to it, right? So I add my custom font to the array.

But when I go to the admin tool, my custom font menu item is not there.

What did I miss here?

6
  • Do you make the check of "if function exists" in your child theme, or this is a check in the parent theme?
    – vlood
    Commented Dec 29, 2014 at 20:57
  • it was in parent, but I also did it in the child theme. I heard that's it's good practice.
    – Steve
    Commented Dec 29, 2014 at 20:59
  • 3
    Override parent theme functions is quite easy and it seems that you are doing right. But we can not know why it is not working in your particular case for the "font menu"; we don't know how that "font menu" works or how it is coded. You should ask to the theme developer.
    – cybmeta
    Commented Dec 29, 2014 at 21:31
  • Thanks. As long as I did it right. I will check with the dev to see if that's the right function to target.
    – Steve
    Commented Dec 29, 2014 at 21:32
  • 2
    I din't try it, but thinking, if ( ! function_exists( 'wpex_standard_fonts' ) ) { will return yes there is a function in the parent theme - isn't that? Commented Dec 30, 2014 at 4:32

1 Answer 1

1

Since you are using a Child Theme, the functions.php file in there is loaded before the parent theme's functions.

So, if you define some_function() in the Child Theme, any declaration of that function in the parent theme will fail. If the parent theme is using a function_exists() to check if some_function() is defined, it should find the function as already being defined, so the parent function will not be loaded.

So, your code to check if the function_exists() is not really needed - since you are in a Child Theme. Only if the parent theme does not do a function_exists for some_function() will there be issues - possibly fatal errors that will disrupt the site.

Your Answer

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

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