How to override a function when isn’t at functions.php

The new function in your child theme’s functions.php cannot override a function from the parent’s functions.php file unless that function is written to be pluggable, i.e. declared with if (!function_exists('alterna_get_social_list'))

Per the documentation on Child Themes and how they inherit from child functions.php files:

Using functions.php
Unlike style.css, the functions.php of a child
theme does not override its counterpart from the parent. Instead, it
is loaded in addition to the parent’s functions.php. (Specifically, it
is loaded right before the parent’s file.)

[https://codex.wordpress.org/Child_Themes#Using_functions.php][1]

Also, and this is super important:

Do not copy the full content of functions.php of the parent theme into
functions.php in the child theme.

The only way to completely re-define a function that isn’t pluggable is if it happens to be added via an action of some sort – then you can first remove the action calling the parent theme’s function and add a new action that calls your new function with a different name.

Leave a Comment