Include file with functions in node.tpl.php and execute them on node content First at all, I know that this isn't the correct way to do this in D7, but I need to do in this way.

I've included a file in node.tpl.php:

include DRUPAL_ROOT . '/sites/all/themes/mytheme/inc/node_functions.php';


In this included file I have a function which, afterwards I want to call from a node's content-body.

Currently, if I call the function from a node content, I get a WSOD. I also checked if within a node-content the function exists, with a PHP function:    

function_exists('name_of_my_function')


but it returns FALSE, so the function no exists in this 'scope'.

In summary, I want a collection of helpful functions included/attached to a node, but I don't want to write the include/require statement everytime I'm creating a node. I only want to simple 'call' those functions. So, how can I do it?

Thanks in advance.
Implementation Issues


Included a file in node.tpl.php
I have a function which, afterwards I want to call from a node's content-body


Sorry but I think these are not following best practices. As you can see If these was possible then it would have worked because it's just including a PHP file and calling a function in it but I think Drupal doesn't do it that way and runs the PHP in the body field way before node.tpl.php w/c results to no included PHP file at that time yet.

Suggested solution

Might I suggest, it's better for us to:


Create a custom module
Add your helper functions there with any structure of the files you can but following Drupal standards.
Use Drupal hooks if needed because if you place your functions in the .module file, it will be available already for use.


One example of this way is after adding your helper functions into the .module file and want to execute/run functions when viewing the node, you can use hook_node_view. Maybe add some scripts, remove data, alter data and etc. and you can also do conditional statements there if you want to run specific things for a specific content type.

This just doesn't align your site with best practices but makes it easier to maintain in the long run with less technical debt.

Hope this helps you to be able to call/execute your needed functions on nodes.

UPDATE

You can remove the PHP file inside your theme and transfer the functions/codes inside it in the .module file. After that, you need to Clear All Caches then that will make your functions available or callable.

You don't need to use the include_once or hook function.