Skip to main content
4 of 4
replaced http://stackoverflow.com/ with https://stackoverflow.com/

Before we get to a solution, let's take a look at how functions work.

Yes, you can call functions in the parent theme from the child theme (though in your example you'll get an error because you pass one variable where two are expected). So, you can add it as a filter in one place and call it independently elsewhere.

When WordPress is loaded it is making an inventory of all available functions. It first loads the child theme's functions.php, then the parent theme's. A function that is redefined in the child, is skipped in the parent. Execution of code only starts after the inventory has been made. Then you can call parent theme functions from the child. You can call plugin functions from your theme, or the other way around. It simply doesn't matter where the function is defined, as long as it is available.

What your function call from the child theme won't do is change the behaviour of the function when it is called as a filter post_thumbnail_html from the get_the_post_thumbnail function. That's two separate calls that are unaware of eachother. So if you want the color from the child function to be applied in the filter, that won't work. To do that, you would have to turn it around. In the parent function call a function from the child (if it exists) and in the child define a function that passes the color.

// parent
if (function_exists (wpse220111_get_child_color))
  $my_color = wpse220111_get_child_color;
else
  $my_color = "#000000";

// child
function wpse220111_get_child_color () {return "#0099dd";}
cjbj
  • 15k
  • 16
  • 42
  • 89