Override a theme function in a child theme?

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?

Topic function-exists functions theme-development Wordpress

Category Web


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.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.