How to call custom function from functions.php in site-wide template files?

It’s worth noting that PHP namespace issues can contribute to this problem. This can catch people because namespaces have been kept out of WordPress core codebase until recently.

For example one of your code files may have a Namespace declaration around the top. If that is the case you will have to prefix any references to the functions with the correct namespace.

In WordPress in particular if there is a mismatch it will not find the function unless it is namespaced correctly.

In themes such as Sage:

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘myplugin_settings’ not found or invalid function name

You would need to indicate the namespace this way. If the namespace is already called above on this file, you need to add the following:

add_action( 'init' , __NAMESPACE__ . '\\myplugin_settings' );

If your file is not in the namespace you will have to add it manually. Note that double-backslashes are needed due to character escaping.

More about namespaces in PHP:

(Adding this answer because I landed here and namespaces were my snag – I didn’t realize the add_action namespace issue.)