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?
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?
Share Improve this question asked Dec 29, 2014 at 20:34 SteveSteve 3139 silver badges21 bronze badges 6 | Show 1 more comment1 Answer
Reset to default 1Since 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.
if ( ! function_exists( 'wpex_standard_fonts' ) ) {
will return yes there is a function in the parent theme - isn't that? – Mayeenul Islam Commented Dec 30, 2014 at 4:32